Forum Moderators: open

Message Too Old, No Replies

JavaScript Error in Netscape document.getElementsByTagName

document.getElementsByTagName not a function error

         

jennashton

6:02 pm on May 27, 2004 (gmt 0)

10+ Year Member



I need help trouble shooting the below script in netscape. It seems to work with IE 5+ and Opera. But it does not work in Netscape 4.x I am getting document.getElementsByTagName is not a function error when submit is pressed in Netscape.
Please help. Thanks ahead.


<script type="text/javascript">

function getRadio(radioName){
var ret = null;
var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++){
if(inputs[i].type.toLowerCase() == 'radio'){
if(inputs[i].name == radioName && inputs[i].checked){
ret = inputs[i].value;
}
}
}
return ret;
}

</script>
</head>

<body>
<form method="post" onsubmit="location.href = getRadio('test1'); return false;">
<input type="radio" name="test1" value="http://www.yahoo.com" checked>A
<input type="radio" name="test1" value="http://www.google.com">B
<P>
<input name="submit" type="image" value="submit">
</P>
<p>
</form>
<form method="post" onsubmit="location.href = getRadio('test2'); return false;">
<input type="radio" name="test2" value="http://www.cnn.com" checked>A
<input type="radio" name="test2" value="http://www.web.com">B
<P>
<input name="submit" type="image" value="submit">
</P>
<p>
</form>

DrDoc

6:05 pm on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Older browsers do not support getElementBy·····

For older Netscape you need to use document.layers
For older Internet Explorer you need to use document.all

jennashton

6:11 pm on May 27, 2004 (gmt 0)

10+ Year Member



ouch...didn't work when I changed

var inputs = document.layers('input');

DrDoc

6:35 pm on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, it wouldn't... document.layers('input') is looking for an element with the name/id "input". Instead, you need to check the
elements
array...