PHILIPS Posted March 18, 2007 Share Posted March 18, 2007 hello, im doing my A levels and i was wondering if any1 can help me on this coursework. basically i have to set up a educational web site that tests students. I am able to create questions, (below is my poor attempt) but the script does not work. can any1 help me please, i would be very gratefull. thank you <BODY><form name="q" action=" "><p>What is 5+5?</p><input type="radio" name="fi" >4<br><input type="radio" name="fi" >10<br><input type="radio" name="fi" >12<br><input type="button" value="Check!" onclick="checkIt()"></form><script>function checkIt(){if (q.fi[1].checked){alert("Thats right!");}else{alert("Go back to kindergarden!!!");}}</script>If any body knows how to create questions better please advice me. im still learning :// Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 18, 2007 Share Posted March 18, 2007 Try document.q.f[1].checked)... didnt the code that I give you word properly?? Link to comment Share on other sites More sharing options...
PHILIPS Posted March 18, 2007 Author Share Posted March 18, 2007 Try document.q.f[1].checked) what do u mean?. i dnt understand, sorry Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 18, 2007 Share Posted March 18, 2007 if (document.q.fi[1].checked){alert("Thats right!");}else{alert("Go back to kindergarden!!!");}} Link to comment Share on other sites More sharing options...
PHILIPS Posted March 18, 2007 Author Share Posted March 18, 2007 yeh i have tried that, but when i click check, nothing happens. so frustrating :// Link to comment Share on other sites More sharing options...
Anders Moen Posted March 18, 2007 Share Posted March 18, 2007 Are you able to use PHP? Then this code works. I've tried it on localhost <?phpif (isset($_POST['submit']) AND ($_POST['fi'] == 10)) {echo 'Congratulations! You answered "10" which is completly right!';}else if (isset($_POST['submit'])) {echo 'Ehh...don\'t you even know what 5+5 is? I really think you are a dumb person! Haha!';}?><form method="post" action=""><p>What is 5+5?</p><input type="radio" name="fi" value="4">4<br><input type="radio" name="fi" value="10">10<br><input type="radio" name="fi" value="12">12<br><input type="submit" name="submit" value="Check!"></form> Oh by the way, I might have misunderstood this totally though, but hopefully this is what you meant Link to comment Share on other sites More sharing options...
jesh Posted March 20, 2007 Share Posted March 20, 2007 Rather than execute the checkIt() function on the click event of the submit button, try executing it on the submit event of the form. I think what is happening is that your code is trying to execute and the form is being submitted to "".Try this: <form name="q" action=" " onsubmit="checkIt(); return false;"><p>What is 5+5?</p><input type="radio" name="fi" />4<br /><input type="radio" name="fi" />10<br /><input type="radio" name="fi" />12<br /><input type="button" value="Check!"></form> Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 21, 2007 Share Posted March 21, 2007 Yup, I tested that code, it worked at my comp on FF Link to comment Share on other sites More sharing options...
PHILIPS Posted March 21, 2007 Author Share Posted March 21, 2007 yeh i have, thx for your help guys Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 21, 2007 Share Posted March 21, 2007 your welcome 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