user1067742
user1067742

Reputation: 31

OnChange event does not work properly

My OnChange event does not work properly - I want to trigger a function when user changes a textbox's value. But in my tests I have seen that the function triggers when textbox's value changes and textbox loses focus. Something wrong with my browser? Or is it about the ability of JavaScript? If the last one is true how can I can do that? Thanks in advance.

Upvotes: 2

Views: 1900

Answers (3)

Amr Elgarhy
Amr Elgarhy

Reputation: 69032

onchange event will trigger when an input field loses focus or when an option is selected from a dropdown menu, that's normal behavior.

If you want an event that will be triggered as the user types in an input field, you can use onkeypress, onkeydown or onkeyup events.

Upvotes: 3

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

write the jquery code on keyup event and blur event also, because if user paste some copied data into textbox by using mouse only in that case only blur event called by jquery.

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

You could do with jquery:

$("textbox_id").keyup(function(){
   //do something here
});

Upvotes: 0

Related Questions