Forum Moderators: open

Message Too Old, No Replies

working with radio buttons

radio buttons

         

bimpe

12:49 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



am using four radio buttons on a form as answer to a question, i want to check for two things
1. if the user has not chosen one of them:to notify the user to choose an answer with yes/no confirmation box, if yes i want to answer, d page remains and if no, another page is loaded
2. if the one chosen is the correct one:to diplay "correct" for d correct answer and "incorrect" for the incorrect answer.
can anyone help me out pls, its very urgent

Alternative Future

1:34 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello and Welcome to WebmasterWorld bimpe,

>>1. if the user has not chosen one of them:to notify the user to choose an answer with yes/no confirmation box, if yes i want to answer, d page remains and if no, another page is loaded

I think the script below shall do what you are trying to do.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="JavaScript">
function checkForm(myForm){
if (!myForm.question[0].checked&&!myForm.question[1].checked) {
var choice = confirm("Do you want to choose an answer?");
if (choice) {
return false;
}else {
myForm.action = "pageD.html";
}
}
}
</script>

</head>
<body>
<form onSubmit="checkForm(this)">
<input type="radio" name="question" value="yes">Yes <input type="radio" name="question" value="no">No
<input type="submit" value="Submit">
</form>

</body>
</html>

>>2. if the one chosen is the correct one:to diplay "correct" for d correct answer and "incorrect" for the incorrect answer.

Not sure I fully understand what your requirements are here, can you give a little more of an explanation?

-George

bimpe

3:38 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



i mean i have 4 options to a question and i want to display a message when either d correct one is chosen or not. diplay "u have choosen the correct ans" when option choosen is the correct one and to diplay "u have choosen the wrong ans/n click on tip for tip to the right answer" when option choosen is the wrong one

Alternative Future

4:54 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello again,

Something like this? :-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="JavaScript">
function checkAnswer(answer){
if(answer == "AnswerB"){
alert("Yahoo... You are correct!");
}else{
var choice = confirm("You have choosen an incorrect answer. Do you want a tip?");
if (choice) {
window.open("", "QuestionTip", 'toolbar=0,width=150,height=100') ;
}else {
return false;
}
}
}
</script>
</head>
<body>
<form>
<input type="radio" name="question" value="AnswerA" onclick="checkAnswer(this.value);">AnswerA<br>
<input type="radio" name="question" value="AnswerB" onclick="checkAnswer(this.value);">AnswerB <i>This one is correct</i><br>
<input type="radio" name="question" value="AnswerC" onclick="checkAnswer(this.value);">AnswerC<br>
<input type="radio" name="question" value="AnswerD" onclick="checkAnswer(this.value);">AnswerD<br>
</form>
</body>
</html>

-George