What event is triggered when a user clicks the X in a search input field (in webkit browsers) to cancel the search or clear the text?
Information is available about restyling the button and other custom events, but not on using this button.
The input event fires when the value of an <input> , <select> , or <textarea> element has been changed. The event also applies to elements with contenteditable enabled, and to any element when designMode is turned on.
The oninput event occurs when an element gets user input. This event occurs when the value of an <input> or <textarea> element is changed.
Answer: Use the value Property You can simply use the value property of the DOM input element to get the value of text input field. The following example will display the entered text in the input field on button click using JavaScript.
<input type="search"> <input> elements of type search are text fields designed for the user to enter search queries into. These are functionally identical to text inputs, but may be styled differently by the user agent.
The onsearch event is triggered both when the search input is submitted and when the user clears the search.
<input type=search onsearch="javascript:alert('SEARCH: ' + this.value);" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With