Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening a new page when correct option is selected

    Hopefully this is quite a simple question for someone to answer as I have been searching endlessly to no avail
    I want to design a simple online test using JavaScript Validation
    I have started with the following code

    <html>
    <head>

    </head>
    <body>
    <h1> What colour is blue </h1>

    <script LANGUcolour="JavaScript">
    <!--
    function ValidateForm(form){
    ErrorText= "";
    if ( form.colour.selectedIndex == 0 ) { alert ( "Please Select an option" ); return false;
    }
    if ( form.colour.selectedIndex == 1 ) { alert ( "That is Incorrect, Try Again" ); return false;
    }
    if ( form.colour.selectedIndex == 2 ) { alert ( "Congratulations You May Proceed" ); return true;
    }
    if ( form.colour.selectedIndex == 3 ) { alert ( "That is Incorrect, Try Again" ); return false;
    }
    if ( form.colour.selectedIndex == 4 ) { alert ( "That is Incorrect, Try Again" ); return false;
    }
    if ( form.colour.selectedIndex == 5 ) { alert ( "That is Incorrect, Try Again" ); return false;
    }
    if (ErrorText= "") { form.submit() }
    }
    -->
    </script>
    <br><form name="feedback" action="mailto:me@emailaddress.com" method=post>
    Your Answer:
    <select name="colour"> <option value="">Please Select an Option:</option>
    <option value="black">black</option>
    <option value="blue">blue</option>
    <option value="yellow">yellow</option>
    <option value="red">red</option>
    <option value="green">green</option> </select>

    <input type="button" name="SubmitButton" value="Check Answers" onClick="ValidateForm(this.form)">
    <input type="reset" value="Reset">
    </form>
    </body>
    </html>
    Basically when the correct answer is entered in this case blue not only do I want the message window to open, I either want to open a new html page with a different question or make another question visible (whichever is easier/ preferably both if it is a long test). The post function is not essential at this stage but would be nice if I got emails advising me of incorrect or correct answers. I was playing around with adding something like form action="next.html" method="OPEN" to the validation statement when it returns a correct answer.
    Obviously when an incorrect answer is given then the person cannot proceed until the correct answer is entered
    If anyone can help me out it would be greatly appreciated as I said have been having a bit of trouble working out how to do this. Thank you in advance to all of you that endeavor to try and help me out on this one
    Thank you

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    The easier is to direct to the next page for a question when the correct answer is selected:
    Code:
    if ( form.colour.selectedIndex == 2 ) { alert ( "Congratulations You May Proceed" ); return true;
    location.href='newquestion.htm' ; // URL of the new question.
    }
    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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