Connecting Tech Pros Worldwide Help | Site Map

Code working in IE but not Netscape 7.0

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 12:01 PM
John Wilson
Guest
 
Posts: n/a
Default Code working in IE but not Netscape 7.0

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>

  #2  
Old July 20th, 2005, 12:01 PM
kaeli
Guest
 
Posts: n/a
Default Re: Code working in IE but not Netscape 7.0

In article <41a360b5.0311211018.460b1afe@posting.google.com >,
jwilson@exeter.edu enlightened us with...[color=blue]
> 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">[/color]

deprecated.
<script type="text/javascript">
[color=blue]
> <!--
> function handleClick(){
> var obj = document.getElementById("comment");[/color]

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

  #3  
Old July 20th, 2005, 12:01 PM
Keith Bowes
Guest
 
Posts: n/a
Default Re: Code working in IE but not Netscape 7.0

kaeli wrote:[color=blue]
> In article <41a360b5.0311211018.460b1afe@posting.google.com >,
> jwilson@exeter.edu enlightened us with...
>[color=green]
>>function handleClick(){
>> var obj = document.getElementById("comment");[/color]
>
> 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"]
>[/color]

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

  #4  
Old July 20th, 2005, 12:01 PM
David Dorward
Guest
 
Posts: n/a
Default Re: Code working in IE but not Netscape 7.0

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

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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.