Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Code working in IE but not Netscape 7.0

Reply
Thread Tools

Code working in IE but not Netscape 7.0

 
 
John Wilson
Guest
Posts: n/a
 
      11-21-2003
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>
 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      11-21-2003
In article < >,
enlightened us with...
> 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.
<script type="text/javascript">

> <!--
> 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

 
Reply With Quote
 
 
 
 
Keith Bowes
Guest
Posts: n/a
 
      11-21-2003
kaeli wrote:
> In article < >,
> enlightened us with...
>
>>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)

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      11-21-2003
John Wilson wrote:

> 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">

--
David Dorward http://dorward.me.uk/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netscape is working but IE isn't henrichs_1@hotmail.com Computer Support 5 02-18-2007 09:43 PM
Not working in Netscape: but it is in IE and firefox eroot@telus.net Javascript 14 07-15-2005 01:52 AM
Code works in Netscape 7.1 but not IE ---- document.getElementById('other').style.visibility='hidden'; lawrence Javascript 3 09-30-2004 06:22 AM
Script is working in IE, but not working in Netscape 7 - trouble with document.selection.createRange(); lawrence Javascript 8 05-05-2004 01:43 AM
Code works in IE but not Netscape/Mozilla Keegan Alex Javascript 1 07-30-2003 01:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57