addEventListener("search", myFunction); - Javascript DOM Event

Javascript examples for DOM Event:addEventListener

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").addEventListener("search", myFunction);

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

</body>
</html>

Related Tutorials