| | |
Firefox and chained select menus
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi all,
I have a problem with a script that is driving me round the bend and I do hope someone can shed some light on the matter. I am new to Javascript and need a nudge in the right direction.
I have three select menus - Country, Region and County.
If you select a Country, the Region menu updates. If you then choose a Region, the County menu updates.
I have used a script from GreatASP.co.uk and, after a small amount of fiddling and a large amount of swearing, I have this working in IE but Firefox doesn't even try:
In the original version from GreatASP, the author puts the following line about the function declaration, but I have found that this actually stops the code from working in IE.
Obviously, I changed the variable name and div name to suit.
I can see what it's for, in that you have to define the variable before the function calls it - indeed, Firefox warns me in the error console if the above line(s) are not included, but still doesn't work when I put them in. It says regiondiv is not defined.
The DOCTYPE of the HTML file is 4.01 Transitional if that helps at all.
The HTML that calls the function is:
I have tried replacing various parts of the code with getElementById calls but nothing seems to work. The above code is the only variation of dozens that seems to work in IE and I have never got it to do anything in Firefox.
I realise I have 3 SELECTs called Area - this is because the form needs to produce a URL string that groups Country, Region and County together, separated by commas.
Please help!
Thanks.
I have a problem with a script that is driving me round the bend and I do hope someone can shed some light on the matter. I am new to Javascript and need a nudge in the right direction.
I have three select menus - Country, Region and County.
If you select a Country, the Region menu updates. If you then choose a Region, the County menu updates.
I have used a script from GreatASP.co.uk and, after a small amount of fiddling and a large amount of swearing, I have this working in IE but Firefox doesn't even try:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<SCRIPT LANGUAGE="Javascript"> function getSelect(selectname,selection,recordset,destination){ if(selection!=''){ var doc = null; // Make a new XMLHttp object if (typeof window.ActiveXObject != 'undefined' ) { doc = new ActiveXObject("Microsoft.XMLHTTP"); } else { doc = new XMLHttpRequest(); } // Load the result from the response page if (doc){ doc.open("GET", "populate.asp?selectname="+selectname+"&selection=" + selection+"&recordset="+recordset, false); doc.send(null); // Write the response to the div destination.innerHTML = doc.responseText; }else{ destination.innerHTML = 'Browser unable to create XMLHttp Object'; } }else{ // Return the next select box back to the default destination.innerHTML= '<select><option value=""></option></select>'; } selectname= null selection = null recordset = null } </SCRIPT>
In the original version from GreatASP, the author puts the following line about the function declaration, but I have found that this actually stops the code from working in IE.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
// declare new variables for each new div that you add, and link to the div by ID var subcatdiv = document.getElementById("subcat_div");
Obviously, I changed the variable name and div name to suit.
I can see what it's for, in that you have to define the variable before the function calls it - indeed, Firefox warns me in the error console if the above line(s) are not included, but still doesn't work when I put them in. It says regiondiv is not defined.
The DOCTYPE of the HTML file is 4.01 Transitional if that helps at all.
The HTML that calls the function is:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<DIV ID="countrydiv"> <SELECT NAME="Area" onchange="getSelect('Area', this.value,'Region',regiondiv);"> <OPTION>Country1</OPTION> <OPTION>Country2</OPTION> </SELECT> </DIV> <DIV ID="regiondiv"> <SELECT NAME="Area" onChange="getSelect('Area', this.value,'County',countydiv);"> </SELECT> </DIV> <DIV ID="countydiv"> <SELECT NAME="Area"> <OPTION></OPTION> </SELECT> </DIV>
I have tried replacing various parts of the code with getElementById calls but nothing seems to work. The above code is the only variation of dozens that seems to work in IE and I have never got it to do anything in Firefox.
I realise I have 3 SELECTs called Area - this is because the form needs to produce a URL string that groups Country, Region and County together, separated by commas.
Please help!
Thanks.
<SCRIPT LANGUAGE="Javascript"> is depreciated, use type instead:
<script type="text/javascript">
capital tags are not needed by the way, just so you know : - )
Your problem probably lies here:
When you call getSelect(), you are forgetting to put single quotes around the div's name too.
<script type="text/javascript">
capital tags are not needed by the way, just so you know : - )
Your problem probably lies here:
html Syntax (Toggle Plain Text)
<DIV ID="countrydiv"> <SELECT NAME="Area" onchange="getSelect('Area', this.value,'Region','regiondiv');"> <OPTION>Country1</OPTION> <OPTION>Country2</OPTION> </SELECT> </DIV> <DIV ID="regiondiv"> <SELECT NAME="Area" onChange="getSelect('Area', this.value,'County','countydiv');"> </SELECT> </DIV>
When you call getSelect(), you are forgetting to put single quotes around the div's name too.
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi,
Thanks very much for your help.
I tried the code with the apostrophe around the div name in the getSelect as suggested, and changed the language to type. Firefox still refuses to work. I also tried adding in the code that I had left out and that broke IE, as usual.
Could there be a conflict in that I have my SELECTs with the same name of 'Area' ?
Annoyingly, even though I have copied the code from GreatASP, his example on that site works in Firefox.
Any other ideas much appreciated!
Thanks very much for your help.
I tried the code with the apostrophe around the div name in the getSelect as suggested, and changed the language to type. Firefox still refuses to work. I also tried adding in the code that I had left out and that broke IE, as usual.
Could there be a conflict in that I have my SELECTs with the same name of 'Area' ?
Annoyingly, even though I have copied the code from GreatASP, his example on that site works in Firefox.
Any other ideas much appreciated!
•
•
•
•
Could there be a conflict in that I have my SELECTs with the same name of 'Area' ?
Please also make sure you changed the whole thing:
<script type="text/javascript">
and NOT
<script type="javascript">
Good luck
Last edited by brechtjah; Dec 12th, 2008 at 6:46 am.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: AJAX FF/Mozilla Form Woes
- Next Thread: external JS for quote rotator
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





