Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a New page when correct option selected

Status
Not open for further replies.

J10000

IS-IT--Management
Oct 2, 2008
6
AU
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
 
I know this doesn't answer your question, but as an aside, doing tests like this in JS is always a bad idea, as anyone can right-click, view the source, and immediately see the correct answer(s).

For this reason alone, I'd give up on doing your validation client-side and move it all to be server-side.

It's akin to doing password validation client-side when people can view the source and see the correct password.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I would start by having a close look at your code... I expect you've corrupted your source through copy/paste:
Code:
<script LANGUcolour="JavaScript">
This would be written:
Code:
<script type="text/javascript">
Note that the language attribute has been deprecated.

Maybe it's a good idea to get one of those "teach yourself javascript" books, or start doing some of the excellent online tutorials on the internet... because I think you've stepped into this problem a little out of your depth.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top