473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

form.onchange

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
1 5966
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish...
2
by: Phil Powell | last post by:
I have a form with two single-choice dropdowns. Upon doing an onChange event on either one of them, I want to check to see if the other dropdown has also been selected. How would I do that,...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
2
by: lmeng | last post by:
Hi, I am new to this Forum. Thanks in advance for any kind help. In the following HTML code, when I change the value of one text field then click "Modify" button, if the validation fails a...
4
by: Sen | last post by:
This is the Javascript function: function auto_submit(form_name, value) { document.form_name.elements.click(); } This is the XHTML: <select name="category"...
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
2
by: Martin | last post by:
I am writing a javascript object and once complete i will create an instance of the object to use in my webpage. Within the object constructor i create a form with a select list in it, the form...
3
by: chifm | last post by:
Hi ALL, I dont know much about php, but have got a long form that i need to split into two pages, i want to have the inputs from the page 1 past to page 2 and all submitted via email at the end. I...
13
by: DDragon | last post by:
ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.