/    Sign up×
Community /Pin to ProfileBookmark

how to track changes in input elements

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);[/COLOR]
}
}
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 17.2008 — <i>
</i>e.onchange=function(){setValueChanged(true)}
×

Success!

Help @bk4web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...