...

View Full Version : Javascript onchange event handler help



ikilledsanta
03-11-2009, 02:27 AM
Hi, I'm building a site for a friend, and he wants to include a price calculator that updates any time a text input (input type=text, not textarea), checkbox, or select is changed. I could add the HTML onChange attribute to every input tag, but that would be tedious, not to mention a waste of space.

I tried using document.getElementsByTagName('input').onchange=function() but that didn't work :(. Any ideas?

Old Pedant
03-11-2009, 07:30 AM
var flds = document.getElementsByTagName("input");
for ( f = 0; f < flds.length; ++f )
{
var fld = flds[f];
if ( fld.type == "text" ) // I think this is right type, but check it with an alert maybe?
{
fld.onchange = function....
}
}

ikilledsanta
03-16-2009, 11:24 PM
var flds = document.getElementsByTagName("input");
for ( f = 0; f < flds.length; ++f )
{
var fld = flds[f];
if ( fld.type == "text" ) // I think this is right type, but check it with an alert maybe?
{
fld.onchange = function....
}
}


This worked perfectly, thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum