Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

firefox specific getElementById error

Status
Not open for further replies.

keak

Programmer
Joined
Sep 12, 2005
Messages
247
Location
CA
Hi there, I have the followign code segment in Javascript:
Code:
var game = document.getElementById("game").options[document.getElementById("game").selectedIndex].text;

and this works just fine in IE. But when I run this exact same code in firefox, I am getting the error

Error: document.getElementById("game") has no properties

Wondering if anyone have come accross similar problems.
 
I got the same error in Firefox if I leave id='game' off of the select.

Code:
<select [b]id='game'[/b] name='game'
onchange="runthis(); return false;">
<option value="1">Chess</option>
<option value="2">Checkers</option>
<option value="3">BackGammon</option>
</select>
<script>
function runthis() {
var game = document.getElementById("game").options[document.getElementById("game").selectedIndex].text;
alert(game);
}
</script>
Make sure that is in your select statement and try it again.

Rois
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top