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

Script works in IE 6 but not Firefox

Status
Not open for further replies.

jloffredo

Technical User
Joined
Feb 24, 2002
Messages
17
Location
US
I have a script that works fine in IE 6 but not in Firefox. I get the following error when debugging:

document.getElementById("routput") has no properties

Below is a small example to demonstrate


<form name="adder" method="post">

1<input type="radio" name="r1"checked section="0" value="1" onClick="addIt()" >
<br>

2<input type="radio" name="r1" section="0" value="2" onClick="addIt()" >
<br>
<br> <br>

3<input type="radio" name="r2"checked section="1" value="3" onClick="addIt()" >
<br>

4<input type="radio" name="r2" section="1" value="4" onClick="addIt()" >
<br>



Total<input name="routput" size="4" value="0" maxlength="10">

</form>

<SCRIPT type=text/javascript>
<!--

function addIt(){


sec1 = document.getElementsByName('r1');

sec2 = document.getElementsByName('r2');

for (i=0; i<sec1.length; i++)
{if (sec1.checked == true){val1 = sec1.value}}

for (i=0; i<sec2.length; i++)
{if (sec2.checked == true){val2 = sec2.value}}


currTotal = parseFloat(val1)+parseFloat(val2)
shipIndex=0
document.getElementById('routput').value = currTotal

}


//-->
</SCRIPT>


I direction of how to modify to work in Firefox would be appreciated.

Thanks
 
Simple - change "name=routput" to "id=routput"... or add the id as well as the name.

The clue is in the method name - getElement[!]ById[/!] and yet you had no id. IE lets people get away with sloppy coding - a pitfall which you've just found.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan, that was the problem

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top