Computing.Net > Forums > Web Development > script works in IE not Netscape

script works in IE not Netscape

Reply to Message Icon

Original Message
Name: Ron_Hunter
Date: November 8, 2004 at 07:17:11 Pacific
Subject: script works in IE not Netscape
OS: xp
CPU/Ram: P4 516
Comment:

I've pasted the contents of a page that has an example of the selection from a combo determining the contents of other combos. It works ok in IE but not in Netscape. Id be gratefull if anyone could tell me why!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scottish Schools Athletic Association entry form</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff topMargin=0>
<form action="http://" method="POST" name="entry_details" id="entry_details">
size=5 face="Arial, Helvetica, sans-serif">


<select name="g_age" id="select2" onChange="populate_it(g_age.options.value)">
<option value="0" selected>Available Groups</option>
<option value="1" >Girls under 16</option>
<option value="2">Girls over 16</option>
<option value="3">Boys under 16</option>
<option value="4">Boys over 16</option>
</select>

Eventsize=4>
<select name="event1" id="event1">
<option value="1">Events available</option>
</select>


Eventsize=4>
<select name="event2" id="event2">
<option value="1">Events available</option>
</select>


Eventsize=4>
<select name="event3" id="event3">
<option value="1">Events available</option>
</select>


Eventsize=4>
<select name="event4" id="event4">
<option value="1">Events available</option>
</select>


Eventsize=4>
<select name="event5" id="event5">
<option value="1">Events available</option>
</select>


Eventsize=4>
<select name="event6" id="event6">
<option value="1">Events available</option>
</select>
</p>


<script>
<!--

/*
Double Combo Script Credit
By Website Abstraction (www.wsabstract.com)
Over 200+ free JavaScripts here!
*/

var groups=document.entry_details.g_age.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
group[1][0]=new Option("Events Available","0")
group[1][1]=new Option("60m","1")
group[1][2]=new Option("60m Hurdles","2")
group[1][3]=new Option("200m","3")
group[1][4]=new Option("400m","4")
group[1][5]=new Option("800m","5")
group[1][6]=new Option("1500m","6")
group[1][7]=new Option("Shot Putt","7")
group[1][8]=new Option("High Jump","8")
group[1][9]=new Option("Long Jump","9")

group[2][0]=new Option("Events Available","0")
group[2][1]=new Option("60m","1")
group[2][2]=new Option("60m Hurdles","2")
group[2][3]=new Option("200m","3")
group[2][4]=new Option("400m","4")
group[2][5]=new Option("800m","5")
group[2][6]=new Option("1500m","6")
group[2][7]=new Option("Shot Putt","7")
group[2][8]=new Option("High Jump","8")
group[2][9]=new Option("Long Jump","9")
group[2][10]=new Option("Pole Vault","10")

group[3][0]=new Option("Events Available","0")
group[3][1]=new Option("60m","1")
group[3][2]=new Option("60m Hurdles","2")
group[3][3]=new Option("200m","3")
group[3][4]=new Option("400m","4")
group[3][5]=new Option("800m","5")
group[3][6]=new Option("1500m","6")
group[3][7]=new Option("Shot Putt","7")
group[3][8]=new Option("High Jump","8")
group[3][9]=new Option("Long Jump","9")

group[4][0]=new Option("Events Available","0")
group[4][1]=new Option("60m","1")
group[4][2]=new Option("60m Hurdles","2")
group[4][3]=new Option("200m","3")
group[4][4]=new Option("400m","4")
group[4][5]=new Option("800m","5")
group[4][6]=new Option("1500m","6")
group[4][7]=new Option("Shot Putt","7")
group[4][8]=new Option("High Jump","8")
group[4][9]=new Option("Long Jump","9")
group[4][10]=new Option("Pole Vault","10")

var temp1=document.entry_details.event1
var temp2=document.entry_details.event2
var temp3=document.entry_details.event3
var temp4=document.entry_details.event4
var temp5=document.entry_details.event5
var temp6=document.entry_details.event6

function populate_it(x){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for (m=temp2.options.length-1;m>0;m--)
temp2.options[m]=null
for (m=temp3.options.length-1;m>0;m--)
temp3.options[m]=null
for (m=temp4.options.length-1;m>0;m--)
temp4.options[m]=null
for (m=temp5.options.length-1;m>0;m--)
temp5.options[m]=null
for (m=temp6.options.length-1;m>0;m--)
temp6.options[m]=null


for (i=0;i<group[x].length;i++){
temp1.options[i]=new Option(group[x][i].text,group[x][i].value)
temp2.options[i]=new Option(group[x][i].text,group[x][i].value)
temp3.options[i]=new Option(group[x][i].text,group[x][i].value)
temp4.options[i]=new Option(group[x][i].text,group[x][i].value)
temp5.options[i]=new Option(group[x][i].text,group[x][i].value)
temp6.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp1.options[0].selected=true
temp2.options[0].selected=true
temp3.options[0].selected=true
temp4.options[0].selected=true
temp5.options[0].selected=true
temp6.options[0].selected=true
}
</script>
</p>
</form>

<P align=center> </P>

 </P>
</BODY></HTML>


Report Offensive Message For Removal


Response Number 1
Name: Don Arnett
Date: November 8, 2004 at 09:31:13 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

It's been a while since I've done web stuff, so I'm not sure this is correct, but it'll be easy to try.

In the line:

var groups=document.entry_details.g_age.options.length

I don't believe that Netscape allows you to use the form names. Try changing the form name (entry_details) to 'forms[0]'.

var groups=document.forms[0].g_age.options.length


Report Offensive Follow Up For Removal

Response Number 2
Name: Dr. Nick
Date: November 8, 2004 at 20:37:12 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

Not looking over the entire thing, but here's a big issue:

The currently suggested way (at least the latest I've seen) to get a handle on the elements of the page is to use the getElementById() method. It's supported by both IE and Mozilla.

IE & Gecko references.

It's what I've used lately and it's a lot easier than accessing elements using an array.


Report Offensive Follow Up For Removal

Response Number 3
Name: Ron_Hunter
Date: November 9, 2004 at 03:50:02 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

Thanks for the replies guys. Dr. Nick I'm a novice as far as scripting is concerned. Any chance of you showing me how to incorporate this into my existing code?

Thanks
Ron


Report Offensive Follow Up For Removal

Response Number 4
Name: Dr. Nick
Date: November 9, 2004 at 16:15:18 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

Sure.

It goes along with what Don was saying. Instead of trying to access elements on the page using document.<element>, do this:

var element = document.getElementById('elementID');

Set the ID attribute for the element in question, then use that inside the getElementById() call. You can then use the variable returned to access child members.

So in your code it looks like you'd want to use this:

var groups = document.getElementById('g_age').options.length

instead of:

var groups=document.entry_details.g_age.options.length

You will want to change the ID of that select element from "select2" to "g_age" for this to work though.

If that doesn't help, try taking a look at the Javascript console in Netscape/Mozilla. It usually gives you a good idea if something is not supported or whatnot. Also, if you put this someplace publicly available, we could take a look at it and give more detailed info... it looks like the forum borked your code pretty good.


Report Offensive Follow Up For Removal

Response Number 5
Name: Ron_Hunter
Date: November 10, 2004 at 04:25:01 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

Thanks Dr Nick.

Borked??


Report Offensive Follow Up For Removal


Response Number 6
Name: Ron_Hunter
Date: November 10, 2004 at 07:31:30 Pacific
Subject: script works in IE not Netscape
Reply: (edit)

Thanks again guys. I'm learning lots from this process. I used the javascript console as you suggested Dr. Nick and it throws up an error 'group[x]has no properties' on the line
for (i=0;i<group[x].length;i++){

Ron


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: script works in IE not Netscape

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge