How can I bind an OnChange event of a TextBox to function using jQuery?
Am trying this and its failing:
$(document).ready(function() {
$(\"input#
Here's a clue why an onchange() call might not fire your bound function:
http://jehiah.cz/archive/firing-javascript-events-properly
What Chad says, except its better to use .keyup in this case because with .keydown and .keypress the value of the input is still the older value i.e. the newest key pressed would not be reflected if .val() is called.
This should probably be a comment on Chad's answer but I dont have privileges to comment yet.
I 2nd Chad Grant's answer and also submit this blog article [removed dead link] for your viewing pleasure.
You must change the event name from "change" to "onchange":
$(document).ready(function(){
$("input#tags").bind("onchange", autoFill);
});
or use the shortcut binder method change:
$(document).ready(function(){
$("input#tags").change(autoFill);
});
Note that the onchange event usually fires when the user leave the input, so for auto-complete you better use the keydown event.
if you're trying to use jQuery autocomplete plugin, then I think you don't need to bind to onChange event, it will
You're looking for keydown/press/up
$("#inputID").keydown(function(event) {
alert(event.keyCode);
});
or using bind $("#inputID").bind('onkeydown', ...
http://docs.jquery.com/Events