www.webdeveloper.com
Results 1 to 7 of 7

Thread: Why does this not work with netscape?

  1. #1
    Join Date
    Oct 2003
    Posts
    6

    Why does this not work with netscape?

    right guys I am using the code below to get a value from a radio box and post it to the window location. It works perfectly with IE but not netscape.

    Any Ideas?

    <script>
    function sorturl() {
    for(i=0; i<question1.q1.length; i++)
    if(question1.q1[i].checked)
    thisans = question1.q1[i].value
    window.location = "p2.htm" + "?x" + thisans
    }
    </script>

    <input type="button" onclick="sorturl()" value="Next Question">

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    Netscape (and W3 reccommendations, BTW) requires that a form element be a child of a <FORM> tag. IE just allows you to be non-compliant.

  3. #3
    Join Date
    Oct 2003
    Posts
    6
    yeah sorry it is part of a form.

  4. #4
    Join Date
    Nov 2002
    Posts
    4,473
    So it would be nice if you would post a link, or zip the file and attach it to your next post.

    That way you will have fewer reasons to be sorry.

  5. #5
    Join Date
    Oct 2003
    Posts
    6
    <html>
    <head>
    <title>Tutorial - Question One</title>
    <script>
    function sorturl() {
    for(i=0; i<question1.q1.length; i++)
    if(question1.q1[i].checked)
    thisans = question1.q1[i].value
    window.location = "p2.htm" + "?x" + thisans
    }
    </script>
    </head>

    <body>
    <center><h2><u>Introduction to Scripting - Tutorial 1</u></h2></center>
    <h4>QUESTION 1</h4>

    <form name="question1">

    <table align="center" border="2" width="600">
    <tr>
    <td width="110"><strong>Question 1</strong></td>
    <td colspan="3">A proven approach to creating web pages is based on the:</td>
    </tr>
    <tr bgcolor="cornsilk" valign="top">
    <td>Option 1</td>
    <td width="450">
    Playdo model
    </td>
    <td><input type="radio" name="q1" value="0" onclick="0"></td>
    </tr>
    <tr bgcolor="cornsilk" valign="top">
    <td>Option 2</td>
    <td width="450">
    spiral model
    </td>
    <td><input type="radio" name="q1" value="1" onclick="0"></td>
    </tr>
    <tr bgcolor="cornsilk" valign="top">
    <td>Option 3</td>
    <td width="450">
    hackers model, if any
    </td>
    <td><input type="radio" name="q1" value="2" onclick="0"></td>
    </tr>
    </table>
    <br>
    <center><input type="button" onclick="sorturl()" value="Next Question">
    </form>
    </body>
    </html>

  6. #6
    Join Date
    May 2003
    Location
    Mordor
    Posts
    454
    There are two problems in your script...

    The first (and this is the one irritating Netscape) is that it is saying question1 is undefined. And sure enough, if you look at the page, question1 is not a property of the window. The form question1 is a property of the document, so you need to change all your references to question1 to document.question1

    The second (and IE has a problem with this too) is that if the user doesn't click any of the radio buttons, then the statement:
    Code:
    thisans = document.question1.q1[i].value
    will never be executed and so the variable thisans will not be defined when you try to build the next page's URL...
    Code:
    window.location = "p2.htm" + "?x" + thisans
    You should probably test whether testans == undefined before moving to the next page.

  7. #7
    Join Date
    Oct 2003
    Posts
    6
    great. got it working now.

    thanks

    JC

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles