onsearch = myFunction(); - Javascript DOM Event

Javascript examples for DOM Event:Element Event Attribute

Description

The onsearch event occurs when a user presses the "ENTER" key or clicks the "x" button in an <input> element with type="search".

Summary

Bubbles No
Cancelable No
Supported HTML tags: <input type="search">

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="search" id="myInput">

<p id="demo"></p>

<script>
document.getElementById("myInput").onsearch = function() {myFunction()};

function myFunction() {//from   w  w w.  ja  v a  2  s  .  co m
    var x = document.getElementById("myInput");
    document.getElementById("demo").innerHTML = "You are searching for: " + x.value;
}
</script>

</body>
</html>

Related Tutorials