Code working in IE but not Netscape 7.0

Discussion in 'Javascript' started by John Wilson, Nov 21, 2003.

  1. John Wilson

    John Wilson Guest

    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>
    John Wilson, Nov 21, 2003
    #1
    1. Advertising

  2. John Wilson

    kaeli Guest

    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
    kaeli, Nov 21, 2003
    #2
    1. Advertising

  3. John Wilson

    Keith Bowes Guest

    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)
    Keith Bowes, Nov 21, 2003
    #3
  4. 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/
    David Dorward, Nov 21, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    486
  2. Keegan Alex

    Code works in IE but not Netscape/Mozilla

    Keegan Alex, Jul 30, 2003, in forum: Javascript
    Replies:
    1
    Views:
    104
    Janwillem Borleffs
    Jul 30, 2003
  3. lawrence
    Replies:
    8
    Views:
    237
    lawrence
    May 5, 2004
  4. lawrence
    Replies:
    3
    Views:
    183
  5. Replies:
    14
    Views:
    172
    Mick White
    Jul 15, 2005
Loading...

Share This Page