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

What is wrong? works in IE but not Netscape 7.2 1

Status
Not open for further replies.

clflyer

Programmer
Nov 26, 2002
6
0
0
US
I have a problem and am wondering if someone else knows the cure. The following code works fine in IE, but it chokes and dies in Netscape 7.2 when I try to use the value from a form field. Instead of an object, Netscape returns a null. Anyone have any ideas? Here is a link to the test page:
<html>

<head>
<script language = "javascript">
function testing()
{
alert("in testing()");
var thefield = document.getElementById("myfield");
alert("thefield = "+thefield);
abc = thefield.value;
alert("abc="+abc);
}

</script>
</head>

<body onLoad="testing()">

<form name="myform">
<p><input type="text" name="myfield" size="20"></p>

<p><input type="button" value="Test It" name="B1" onClick="testing()"></p>

</form>

</body>

</html>
 

Because your field has no id, you cannot expect getElementById to work.

It only works in IE because IE is a bit dumb and gives users far too much leeway, IMHO.

Change the "name" attribute to "id", and all should work as expected.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 

Incidentally, if you need to submit the form, and thus have an id and a name, just add an id attribute instead of renaming the name attribute.

Dan



The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top