I want to fire a common event whenever a value of any element in form changes. On the basis of values of form elements i want implement code.
i am writing below code but onchange event is not working on formid.
$("#formid").change(function () {
//code
});
or this
$("#formid").bind("change", function () {
//code
});
How to fire event on form whenever there is any change in element's value ?
How to fire event on form whenever there is any change in element's value ?
Just do as it looks like you've done. Bind the change
event to the form
element.
$("form").change(function() {
// Some descendant changed.
});
So long as you're not interfering with the propagation of the events, this will work.
You can bind change event for all necessary form controls
$('input, select, textarea', $('#formid')).change(function()
{
//your code here
});
Loop through all elements of your document or form and set their onChange event to your handling function. Like:
for (var i = 0; i < yourelements.length; i++)
yourelements[i].onchange = change;
$(this).toArray().each(function(index, element){
$(element).change(function(){.....});
});
put this in document.ready...