Click to See Complete Forum and Search --> : calculation from the radio button option
hsloh
12-26-2002, 09:26 PM
Can anyone help me in this question ? Please ...it is urgent
I need to do a survey form by using the Javascript.
There are six question in the form. Eash question may have 3 or four options (using radio button). Every question may have the individual score in the radio button option.
After the user has choosen the answer from the six question. The total score will displaying in a text box.
Example:- (I just display two questions here)
Q1. What is your salary range
A. RM2000 - RM3000 (score + 0.5)
B. RM3000 - RM4500 (score + 0)
C. RM5000 - RM6000 (score -0.5)
Q2. What qualification do you have?
A. Diploma (score + 0.5)
B. Degree (score + 0)
c. Master (score - 0.5)
Total score will display : ___________
AdamBrill
12-26-2002, 10:29 PM
Is this what you want?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Question 1</title>
<script language=javascript>
function submit_form(form)
{
for(x=0;x<TheForm.question1.length;x++)
{
if(TheForm.question1[x].checked)
{
Question1=TheForm.question1[x].value;
break;
}
else
{
Question1="";
}
}
for(x=0;x<TheForm.question2.length;x++)
{
if(TheForm.question2[x].checked)
{
Question2=TheForm.question2[x].value;
break;
}
else
{
Question2="";
}
}
for(x=0;x<TheForm.question3.length;x++)
{
if(TheForm.question3[x].checked)
{
Question3=TheForm.question3[x].value;
break;
}
else
{
Question3="";
}
}
for(x=0;x<TheForm.question4.length;x++)
{
if(TheForm.question4[x].checked)
{
Question4=TheForm.question4[x].value;
break;
}
else
{
Question4="";
}
}
for(x=0;x<TheForm.question5.length;x++)
{
if(TheForm.question5[x].checked)
{
Question5=TheForm.question5[x].value;
break;
}
else
{
Question5="";
}
}
for(x=0;x<TheForm.question6.length;x++)
{
if(TheForm.question6[x].checked)
{
Question6=TheForm.question6[x].value;
break;
}
else
{
Question6="";
}
}
if(Question1!="" && Question2!="" && Question3!="" && Question4!="" && Question5!="" && Question6!="")
{
Total=Number(Question1)+Number(Question2)+Number(Question3)+Number(Question4)+Number(Question5)+Numb er(Question6);
TheForm.Total.value=Total;
}
else
{
alert("Please answer all of the questions.");
}
}
</script>
</head>
<body>
<form name=TheForm>
<div style="align:left; width:430; height:90">
Question 1? <br>
<INPUT type="radio" value="1" name="question1">Choice 1<br>
<INPUT type="radio" value="2" name="question1">Choice 2<br>
<INPUT type="radio" value="3" name="question1">Choice 3</div>
<div style="align:left; width:430; height:82">
<p>Question 2? <br>
<INPUT type="radio" value="1" name="question2">Choice 1<br>
<INPUT type="radio" value="2" name="question2">Choice 2<br>
<INPUT type="radio" value="3" name="question2">Choice 3<br>
</div>
<div style="align:left; width:430; height:127">
<p>Question 3? <br>
<INPUT type="radio" value="1" name="question3">Choice 1<br>
<INPUT type="radio" value="2" name="question3">Choice 2<br>
<INPUT type="radio" value="3" name="question3">Choice 3<br>
</div>
<div style="align:left; width:430; height:127">
<p>Question 4? <br>
<INPUT type="radio" value="1" name="question4">Choice 1<br>
<INPUT type="radio" value="2" name="question4">Choice 2<br>
<INPUT type="radio" value="3" name="question4">Choice 3<br>
</div>
<div style="align:left; width:430; height:127">
<p>Question 5? <br>
<INPUT type="radio" value="1" name="question5">Choice 1<br>
<INPUT type="radio" value="2" name="question5">Choice 2<br>
<INPUT type="radio" value="3" name="question5">Choice 3<br>
</div>
<div style="align:left; width:430; height:127">
<p>Question 6? <br>
<INPUT type="radio" value="1" name="question6">Choice 1<br>
<INPUT type="radio" value="2" name="question6">Choice 2<br>
<INPUT type="radio" value="3" name="question6">Choice 3<br>
<br>
<br>
<INPUT type="button" Name="submit" onClick="submit_form(this.form)" value="OK">
<INPUT type="reset" Name="reset" value="reset">
</div>
<INPUT type="text" Name=Total>
</form>
</body>
</html>
Just change what it says and add more or whatever. When they click submit, the values by the Choice that they chose will be added together and go into the variable total (up in the function). I made it so they must answer all of the questions.I hope that's what you want...;)