HTML - attributes - onsearch

revision:


Content

"onsearch" attribute: when the "enter" key or "x" button is pressed. syntax some examples


"onsearch" attribute: when the "enter" key or "x" button is pressed.

top

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

Supported HTML tags: <input type="search">


syntax

top

<element onsearch="script"></element >

script: the script to be run on onsearch.


some examples

top

Write something in the search field and press "ENTER".

codes:
                    <p class="spec">Write something in the search field and press "ENTER".</p>
                    <input style="margin-left:3vw;" type="search" id="myInput" onsearch="searchF()">
                    <p class="spec" id="demo_a"></p>
                    <script>
                        function searchF() {
                        var x = document.getElementById("myInput");
                        document.getElementById("demo_a").innerHTML = "You are searching for: " + x.value;
                        }
                    </script>
                

codes:
                    <input style="margin-left:3vw;" type="search" id="mine" onsearch="searchWhat()">
                    <p class="spec" id="where"></p>
                    <script>
                        function searchWhat() {
                            var x = document.getElementById("mine");
                            document.getElementById("where").innerHTML =  "searching content: " + x.value;
                        }
                    </script>