Code working in IE but not Netscape 7.0

J

John Wilson

Please comment on the following test code. I'd like to understand why
NS will not run this but IE will:

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">
<!--
function handleClick(){
var obj = document.getElementById("comment");
alert(obj.value);
}
// -->
</SCRIPT>

<title>Sample Code</title>

</head>

<body>
<form name="form1" method="post" action="">
<input type="text" name="comment">
<input name="button" type="button" value="clickme"
onClick="handleClick()">
</form>

</body>
</html>
 
K

kaeli

Please comment on the following test code. I'd like to understand why
NS will not run this but IE will:

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

deprecated.
<!--
function handleClick(){
var obj = document.getElementById("comment");

NN4 does not support getElementById()

The comment text element doesn't have an id attached to it anyway, only
a name. I'm surprised IE even handled it. It's a form element with a
name. You didn't give it an id. Even if you did, it's better to use the
forms array.

Use
var obj = document.form1.comment
or
var object = document.forms["form1"].elements["comment"]


--
~kaeli~
A little rudeness and disrespect can elevate a meaningless
interaction to a battle of wills and add drama to an
otherwise dull day.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
K

Keith Bowes

kaeli said:
function handleClick(){
var obj = document.getElementById("comment");

The comment text element doesn't have an id attached to it anyway, only
a name. I'm surprised IE even handled it. It's a form element with a
name. You didn't give it an id. Even if you did, it's better to use the
forms array.

Use
var obj = document.form1.comment
or
var object = document.forms["form1"].elements["comment"]

Or if you must use document.get* methods:
document.getElementsByName('comment').item(0)
 
D

David Dorward

John said:
Please comment on the following test code. I'd like to understand why
NS will not run this but IE will:
var obj = document.getElementById("comment");
<input type="text" name="comment">

You are referencing the element with id "comment" - you don't have an
element with at that id.

<input type="text" name="comment" id="comment">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top