By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

form.onchange

P: n/a
Dear All,

I discovered last night that IE6 doesn't support the onchange event on
the form object. I had written some script in Firefox, and tested in
IE, and spent a long time trying to debug it, only to discover it is
not supported.

But I came up with a work around, which I post here for posterity:

Firefox version:
with( document.getElementById('myForm') )
{
onchange = function() { doMyStuff(); }
}

Internet Explorer version:
with( document.getElementById('myForm') )
{
for( var i = 0 ; length i ; i++ )
{
var element = elements[i];
element.priorfunc = element.onchange;
element.onchange = function()
{
var ret = true;
if( this.priorfunc )
{
ret = this.priorfunc();
}
doMyStuff();
return ret;
}
}
}

Hurrah!

Stewart
London, UK

Aug 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dear All Again,

Having also noticed that IE6 does not trigger onchange for radio
buttons and checkboxes immediately, but waits until focus has moved
away from the element, this version may be more useful for exactly
duplicating Firefox's behaviour.

See also:
http://groups.google.co.uk/group/com...a2ac02da478c3e
http://groups.google.co.uk/group/com...aa1e41ff1c2f41
http://msdn.microsoft.com/library/de...s/onchange.asp

//-----------------------

with( document.getElementById('myForm') )
{
// This complexity is because Internet Explorer
// does not trigger onchange() on a form object,
// otherwise it would be this one-liner:
// onchange = function() { doMyStuff(); }
for( var i = 0 ; length i ; i++ )
{
var element = elements[i];
if(element.type == "checkbox" ||
element.type == "radio")
{
element.prioronclick = element.onclick;
element.onclick = function()
{
var ret = true;
if( this.prioronclick )
{
ret = this.prioronclick();
}
doMyStuff();
return ret;
}
element.prioronkeypress = element.onkeypress;
element.onkeypress = function()
{
var ret = true;
if( this.prioronkeypress )
{
ret = this.prioronkeypress();
}
doMyStuff();
return ret;
}
}
else
{
element.prioronchange = element.onchange;
element.onchange = function()
{
var ret = true;
if( this.prioronchange )
{
ret = this.prioronchange();
}
doMyStuff();
return ret;
}
}
}
}
Stewart
London, UK

Sep 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.