Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  165] [ 2]  / answers: 1 / hits: 17364  / 11 Years ago, wed, april 24, 2013, 12:00:00

Some browsers like Chrome provide an additional search cancel button on inputs with type=search, as seen in the picture below.



Usually the keyup with an additional check is sufficient to test whether the user deleted the input string (not taking right click into account). However neither keyup nor change get triggered if the user cancels the input via the special cancel button provided by webkit browsers.



Is there some kind of special event for those cancel buttons? Or do I have to check one of the already existing events like click?



Screenshot


More From » jquery

 Answers
9

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... />




[#78659] Tuesday, April 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 2 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;