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
Reply

Join Date: Dec 2008
Posts: 5
Reputation: DorsetBloke is an unknown quantity at this point 
Solved Threads: 0
DorsetBloke DorsetBloke is offline Offline
Newbie Poster

Firefox and chained select menus

 
0
  #1
Dec 8th, 2008
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <SCRIPT LANGUAGE="Javascript">
  2.  
  3. function getSelect(selectname,selection,recordset,destination){
  4.  
  5. if(selection!=''){
  6.  
  7. var doc = null;
  8.  
  9. // Make a new XMLHttp object
  10.  
  11. if (typeof window.ActiveXObject != 'undefined' )
  12. {
  13. doc = new ActiveXObject("Microsoft.XMLHTTP");
  14. }
  15. else
  16. {
  17. doc = new XMLHttpRequest();
  18. }
  19.  
  20. // Load the result from the response page
  21.  
  22. if (doc){
  23. doc.open("GET", "populate.asp?selectname="+selectname+"&selection=" + selection+"&recordset="+recordset, false);
  24. doc.send(null);
  25. // Write the response to the div
  26. destination.innerHTML = doc.responseText;
  27. }else{
  28. destination.innerHTML = 'Browser unable to create XMLHttp Object';
  29. }
  30. }else{
  31. // Return the next select box back to the default
  32. destination.innerHTML= '<select><option value=""></option></select>';
  33. }
  34.  
  35. selectname= null
  36. selection = null
  37. recordset = null
  38.  
  39. }
  40. </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)
  1. // declare new variables for each new div that you add, and link to the div by ID
  2. 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)
  1. <DIV ID="countrydiv">
  2. <SELECT NAME="Area" onchange="getSelect('Area', this.value,'Region',regiondiv);">
  3. <OPTION>Country1</OPTION>
  4. <OPTION>Country2</OPTION>
  5. </SELECT>
  6. </DIV>
  7.  
  8. <DIV ID="regiondiv">
  9. <SELECT NAME="Area" onChange="getSelect('Area', this.value,'County',countydiv);">
  10. </SELECT>
  11. </DIV>
  12.  
  13. <DIV ID="countydiv">
  14. <SELECT NAME="Area">
  15. <OPTION></OPTION>
  16. </SELECT>
  17. </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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: Firefox and chained select menus

 
0
  #2
Dec 8th, 2008
<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:
  1. <DIV ID="countrydiv">
  2. <SELECT NAME="Area" onchange="getSelect('Area', this.value,'Region','regiondiv');">
  3. <OPTION>Country1</OPTION>
  4. <OPTION>Country2</OPTION>
  5. </SELECT>
  6. </DIV>
  7.  
  8. <DIV ID="regiondiv">
  9. <SELECT NAME="Area" onChange="getSelect('Area', this.value,'County','countydiv');">
  10. </SELECT>
  11. </DIV>

When you call getSelect(), you are forgetting to put single quotes around the div's name too.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 5
Reputation: DorsetBloke is an unknown quantity at this point 
Solved Threads: 0
DorsetBloke DorsetBloke is offline Offline
Newbie Poster

Re: Firefox and chained select menus

 
0
  #3
Dec 9th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: Firefox and chained select menus

 
0
  #4
Dec 12th, 2008
Originally Posted by DorsetBloke View Post
Could there be a conflict in that I have my SELECTs with the same name of 'Area' ?
Yes that is very much the problem : ) You have to give each selectbox a unique name.

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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC