I would like to track changes made to all input elements using JavaScript.
I don’t want to use onchange event for each and every input element, instead I am planning to set the onchange event programmatically onload of the JSP page. I am having trouble with this approach. Is there any other way to do that?
// this function is called on load of the JSP page
function setOnChangeEvent(){
// iterate thru all input elements
for (var i=0;i < document.forms[0].elements.length;i++)
{
var e = document.forms[0].elements[i];
// determine type of the input element
if (e.type == “text” || e.type == “checkbox” || e.type == “select-one”|| e.type == “select-multiple” || e.type == “radio”|| e.type == “textarea”){
// set the onchange event property to the input element
[COLOR=”Red”]e.onchange = setValueChanged(true);
}
}
}