PHILIPS Posted March 27, 2007 Share Posted March 27, 2007 hello, I have a small problem i have a small test and every answer is the same, I cannot seem to change the script so it will let me have a different answer. Can anyone help change this please. <form name="q" action=" "><p>What is 5+6?</p><input type="radio" name="ff" >4<br><input type="radio" name="ff" >10<br><input type="radio" name="ff" >11<br><input type="button" value="Check!" onclick="checkIt()"><hr /><hr /><form name="r" action=" "><p>What is 10+6?</p><input type="radio" name="fi" >16<br><input type="radio" name="fi" >10<br><input type="radio" name="fi" >11<br><input type="button" value="Check!" onclick="checkIt()"></form><script>function checkIt(){if (w.ff[2].checked){alert("Thats right!");}else{alert("Go back to kindergarden!!!");}}function checkIt(){if (q.fi[1].checked){alert("Thats right!");}else{alert("Go back to kindergarden!!!");}}</script> Link to comment Share on other sites More sharing options...
pulpfiction Posted March 27, 2007 Share Posted March 27, 2007 Try this code.... to change the answer, modify the variable "ans" in javascript code..... <form name="qtn1" action=" "><p>What is 5+6?</p><input type="radio" value="4" name="ff">4<br><input type="radio" value="10" name="ff">10<br><input type="radio" value="11" name="ff">11<br><input type="button" value="Check!" onclick="checkIt('1')"> </form><hr /><hr /><form name="qtn2" action=" "><p>What is 10+6?</p><input type="radio" value="16" name="fi" >16<br><input type="radio" value="10" name="fi">10<br><input type="radio" value="11" name="fi">11<br><input type="button" value="Check!" onclick="checkIt('2')"></form><script>function checkIt(val){var radioObj;var ans;if (val==1) {radioObj = document.qtn1.ff;ans=11;}else if(val==2) {radioObj = document.qtn2.fi;ans=16;}var radioLength = radioObj.length;alert(radioLength);for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { if(radioObj[i].value==ans) alert('Correct Answer'); else alert('Wrong: Incorrect Answer'); } }}</script> Link to comment Share on other sites More sharing options...
PHILIPS Posted March 28, 2007 Author Share Posted March 28, 2007 thats great it works, but before it answers correct or incorrect, the number 3 pops up. i cnt seem to see why?thanks for your help Link to comment Share on other sites More sharing options...
pulpfiction Posted March 28, 2007 Share Posted March 28, 2007 Oh, was using alert for testing purpose...... try this code. <form name="qtn1" action=" "><p>What is 5+6?</p><input type="radio" value="4" name="ff">4<br><input type="radio" value="10" name="ff">10<br><input type="radio" value="11" name="ff">11<br><input type="button" value="Check!" onclick="checkIt('1')"> </form><hr /><hr /><form name="qtn2" action=" "><p>What is 10+6?</p><input type="radio" value="16" name="fi" >16<br><input type="radio" value="10" name="fi">10<br><input type="radio" value="11" name="fi">11<br><input type="button" value="Check!" onclick="checkIt('2')"></form><script>function checkIt(val){ var radioObj; var ans; if (val==1) { radioObj = document.qtn1.ff;ans=11; } else if(val==2) { radioObj = document.qtn2.fi;ans=16; } var radioLength = radioObj.length; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { if(radioObj[i].value==ans) alert('Correct Answer'); else alert('Wrong: Incorrect Answer'); } } }</script> Link to comment Share on other sites More sharing options...
PHILIPS Posted March 28, 2007 Author Share Posted March 28, 2007 thats brilliant thank you very much. :) *hugs* :E Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now