What event is triggered when the user cancels input via the webkit cancel button?
There is an event for this: oninput
.
Occurs when the text content of an element is changed through the user interface.
The oninput is useful if you want to detect when the contents of a textarea, input:text, input:password or input:search element have changed, because the onchange event on these elements fires when the element loses focus, not immediately after the modification.
Here is a working example;
$('#search').on('input', function(e) {
if('' == this.value) {
alert('Please enter a search criteria!');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="search" name="search" id="search" placeholder="Search..." />
There is an event for this: onsearch.
Actions that invoke the onsearch event:
Pressing the ENTER key or clicking the 'Erase search text' button in a search control.
Here is an example:
HTML:
<input type="search" name="search" id="search" placeholder="Search..." />
jQuery:
$('#search').on('search', function(e) {
if('' == this.value) {
alert("You either clicked the X or you searched for nothing.");
}
});