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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox-correct remain checked, incorrect unchecked

Status
Not open for further replies.

taopeng

Programmer
Dec 3, 2001
10
0
0
US
I want users to use checkboxes to answer a question. They should check 3 boxes out of 6 available. The right answer is 2, 5, 6. If they choose them, the popup will say good. If they choose say 1, 5, 6. The popup will say wrong, try again. Then 1 will be unchecked, 5 and 6 will remain checked. The next time they choose something wrong, say 1 or 3 or 4, the popup will say incorrect game, please do some review. Thanks!!
 
<!-- Questions 1 4 and 6 are wrong
That stuff you said was confusing, but I think this is what you want
-->
<html>
<head>
<script language=&quot;JavaScript&quot;>
<!--
function CheckIt(){
msg = &quot;&quot;;
if (document.frm1.chk1.checked){
msg += &quot;Question 1 wrong&quot;
document.frm1.chk1.checked = false;
} else {
if (document.frm1.chk4.checked){
msg += &quot; Question 4 wrong&quot;
document.frm1.chk4.checked = false;
} else {
if (document.frm1.chk6.checked){
msg += &quot; Question 6 wrong&quot;
document.frm1.chk6.checked = false;
}
}
}
if (msg != &quot;&quot;) {
alert(msg);
}
}
-->
</script>
</head>
<body>
<form name=&quot;frm1&quot;>
question 1 <input type=&quot;checkbox&quot; name=&quot;chk1&quot;>
question 2 <input type=&quot;checkbox&quot; name=&quot;chk2&quot;><br>
question 3 <input type=&quot;checkbox&quot; name=&quot;chk3&quot;>
question 4 <input type=&quot;checkbox&quot; name=&quot;chk4&quot;><br>
question 5 <input type=&quot;checkbox&quot; name=&quot;chk5&quot;>
question 6 <input type=&quot;checkbox&quot; name=&quot;chk6&quot;><br>
<input type=&quot;button&quot; value=&quot;Check&quot; onclick=&quot;CheckIt();&quot;>
</form>
</body>
</html>
 
Thanks so much! I wanted one more thing though. :) I want to give the user a second chance which is also their last chance. If on second try they still click a wrong answer, the message will be &quot;Sorry, you fail.&quot; Can you help me on that? Thank you!
 
<!-- Questions 1 4 and 6 are wrong
That stuff you said was confusing, but I think this is what you want
-->
<html>
<head>
<script language=&quot;JavaScript&quot;>
<!--
NoOfChancesAllowed = 2;
NoTried = 0;
function CheckIt(){
NoTried = NoTried + 1;
msg = &quot;&quot;;
if (document.frm1.chk1.checked){
msg += &quot;Question 1 wrong&quot;
document.frm1.chk1.checked = false;
} else {
if (document.frm1.chk4.checked){
msg += &quot; Question 4 wrong&quot;
document.frm1.chk4.checked = false;
} else {
if (document.frm1.chk6.checked){
msg += &quot; Question 6 wrong&quot;
document.frm1.chk6.checked = false;
}
}
}
if (NoTried >= NoOfChancesAllowed) {
msg = &quot;YOU FAIL !!!&quot;
document.frm1.chk1.disabled=&quot;true&quot;
document.frm1.chk2.disabled=&quot;true&quot;
document.frm1.chk3.disabled=&quot;true&quot;
document.frm1.chk4.disabled=&quot;true&quot;
document.frm1.chk5.disabled=&quot;true&quot;
document.frm1.chk6.disabled=&quot;true&quot;
}
if (msg != &quot;&quot;) {
alert(msg);
}
}
-->
</script>
</head>
<body>
<form name=&quot;frm1&quot;>
question 1 <input type=&quot;checkbox&quot; name=&quot;chk1&quot;>
question 2 <input type=&quot;checkbox&quot; name=&quot;chk2&quot;><br>
question 3 <input type=&quot;checkbox&quot; name=&quot;chk3&quot;>
question 4 <input type=&quot;checkbox&quot; name=&quot;chk4&quot;><br>
question 5 <input type=&quot;checkbox&quot; name=&quot;chk5&quot;>
question 6 <input type=&quot;checkbox&quot; name=&quot;chk6&quot;><br>
<input type=&quot;button&quot; value=&quot;Check&quot; onclick=&quot;CheckIt();&quot;>
</form>
</body>
</html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top