PDA

View Full Version : Form Question



Stylin328
Feb 24th, 2003, 04:18 AM
I dont know if anyone in here can help me of if i should to a different room but I need someones help. For this class i have to make a quiz using html form consisted of 5 questions . This has to use radio buttons and such. basically this has to grade it self. like after i answer the questions using the radio buttons . i hit a submit button and it self grades and posts the grade on that page on another text box. how would i do this. This is what i have so far. Thanks guys i really aprecaites it.

/// <html>
<head>
<title>
My Own 5 question quiz
</title>
<script language="javascript">
var x=0;
if(document.Quiz[1].checked){x=x+1;
if(document.Quiz[2].value="false"){x=x+1;
if(document.Quiz[3].value="false"){x=x+1;
if(document.Quiz[4].value="true"){x=x+1;
if(document.Quiz[5].value="true"){x=x+1;

}
</script>

</head>
<body>
<form name="Quiz" >

First Name: <input type="text" name="first" size=15><br>
<ol>
<li> What does MSMC stand for?<input type="text" name="first" size=15><br><p>
<li>There are 54 states the USA?<br>
<input type="radio" name="question1" value="true">True<br>
<input type="radio" name="question1" value="false">False<p>

<li>In golf, ther are 4 quarters?<br>
<input type="radio" name="question2" value="true">True<br>
<input type="radio" name="question2" value="false">False<p>

<li>BMW stand for Bavarian Auto Works?<br>
<input type="radio" name="question3" value="true">True<br>
<input type="radio" name="question3" value="false">False<br><p>

<li>Professor Phillips has a beard?<br>
<input type="radio" name="question4" value="true">True<br>
<input type="radio" name="question4" value="false">False<br><p>
</ol>

<input type="button" value="Submit">
<input type="text" name="grade" size=2><br>
</form>
</body>
</html>////

sweenster
Feb 24th, 2003, 12:35 PM
for starters you need to give your form an action:

replace <form name="quiz"> with:
<form action="javascript:validate()" name="quiz">

then:


<script language="javascript">
function validate() {
var x=0;
if(document.Quiz[1].checked){x=x+1;}
if(document.Quiz[2].value="false"){x=x+1;}
if(document.Quiz[3].value="false"){x=x+1;}
if(document.Quiz[4].value="true"){x=x+1;}
if(document.Quiz[5].value="true"){x=x+1;}

alert("You Scored "+x+"\nCongratulations.");
}
</script>


haven't tested it and javascript really isn't my thing so i dunno if it will work