Hi,
I want to trigger a javascript function when one of the elements in a specific form has been changed. Is this possible using jquery?
Does anybody has an example how to do this?
thanks,
Bart
Hi,
I want to trigger a javascript function when one of the elements in a specific form has been changed. Is this possible using jquery?
Does anybody has an example how to do this?
thanks,
Bart
If you have a text field like this:
<input type='text' id='myInput'>
You can do this:
function executeOnChange() {
alert('new value = ' + $(this).val());
}
$(function() { // wait for DOM to be ready before trying to bind...
$('#myInput').change(executeOnChange);
});
Here is an example of this in action.
Please note you have to lose focus on the text field in order for the change
event to fire.
If you want to select the input by name instead of ID, you can change $('#myInput')
to $('input[name=myName]')
. For more on selectors, check out the documentation.
Jut write a selector for the items in the form and attach a change handler see http://docs.jquery.com/Events/change#examples
$(function () {
$('form#id input[name=joe]').change( function() { alert('it changed!'); });
} );