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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - Javascript doesn't work in Firefox

Status
Not open for further replies.

floofy7

Programmer
Jul 24, 2006
11
US
It works fine in IE. Any advice?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/JavaScript">
<!--
function comboSend(selectObj) {
// get the index of the selected option
var idx = selectObj.selectedIndex;
// get the value of the selected option
var color = selectObj.options[idx].value;
if((color == "blue") && (form1.number[1].checked))
{
alert("Aha!, Blue and 2 have been selected");
}
if((color == "green") && (form1.number[2].checked))
{
alert("Aha!, Green and 3 have been selected");
}
}

function radioSend(rSend)
{
var rVal = rSend.value;
var cIndex = form1.color.selectedIndex;
if((rVal == "2") && (form1.color.options[cIndex].value == "blue"))
{
alert("2 and Blue");
}
if((rVal == "3") && (form1.color.options[cIndex].value == "green"))
{
alert("3 and Green");
}
}
//-->
</script>
</head>

<body>
<form action="" method="post" name="form1" id="form1" >
<p>
<select name="color" size="1" id="color" onchange="comboSend(this)" >
<option value="none" selected="selected">Select</option>
<option value="red" >Red</option>
<option value="blue" >Blue</option>
<option value="green" >Green</option>
</select>
</p>

<p><input name="number" type="radio" id="1" value="1" onclick="radioSend(this)" />1</p>
<p><input name="number" type="radio" value="2" id="2" onclick="radioSend(this)" />2</p>
<p><input name="number" type="radio" value="3" id="3" onclick="radioSend(this)"/>3 </p>
</form>
</body>
</html>
 
In the function radioSend you refer to form1 as follows:
Code:
...
var cIndex = form1.color.selectedIndex;
...
IE is being "nice" and letting this (incorrect) reference to the form work. No biggie... the trick is to refer to the form a little more specifically:
Code:
...
var cIndex = [!]document.forms['[/!]form1[!]'][/!].color.selectedIndex;
...
Let us know how you go.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top