Jump to content

Online tests


PHILIPS

Recommended Posts

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

Try document.q.f[1].checked)... didnt the code that I give you word properly??

Link to comment
Share on other sites

if (document.q.fi[1].checked){alert("Thats right!");}else{alert("Go back to kindergarden!!!");}}

Link to comment
Share on other sites

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

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

Yup, I tested that code, it worked at my comp on FF

Link to comment
Share on other sites

your welcome

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...