/    Sign up×
Community /Pin to ProfileBookmark

calculation from the radio button option

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 : ___________

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@AdamBrillDec 27.2002 — Is this what you want?

<i>
</i>&lt;html&gt;

&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt;
&lt;title&gt;Question 1&lt;/title&gt;
&lt;script language=javascript&gt;
function submit_form(form)
{
for(x=0;x&lt;TheForm.question1.length;x++)
{
if(TheForm.question1[x].checked)
{
Question1=TheForm.question1[x].value;
break;
}
else
{
Question1="";
}
}
for(x=0;x&lt;TheForm.question2.length;x++)
{
if(TheForm.question2[x].checked)
{
Question2=TheForm.question2[x].value;
break;
}
else
{
Question2="";
}
}
for(x=0;x&lt;TheForm.question3.length;x++)
{
if(TheForm.question3[x].checked)
{
Question3=TheForm.question3[x].value;
break;
}
else
{
Question3="";
}
}
for(x=0;x&lt;TheForm.question4.length;x++)
{
if(TheForm.question4[x].checked)
{
Question4=TheForm.question4[x].value;
break;
}
else
{
Question4="";
}
}
for(x=0;x&lt;TheForm.question5.length;x++)
{
if(TheForm.question5[x].checked)
{
Question5=TheForm.question5[x].value;
break;
}
else
{
Question5="";
}
}
for(x=0;x&lt;TheForm.question6.length;x++)
{
if(TheForm.question6[x].checked)
{
Question6=TheForm.question6[x].value;
break;
}
else
{
Question6="";
}
}
if(Question1!="" &amp;&amp; Question2!="" &amp;&amp; Question3!="" &amp;&amp; Question4!="" &amp;&amp; Question5!="" &amp;&amp; Question6!="")
{
Total=Number(Question1)+Number(Question2)+Number(Question3)+Number(Question4)+Number(Question5)+Number(Question6);
TheForm.Total.value=Total;
}
else
{
alert("Please answer all of the questions.");
}
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name=TheForm&gt;
&lt;div style="align:left; width:430; height:90"&gt;
Question 1? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question1"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question1"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question1"&gt;Choice 3&lt;/div&gt;
&lt;div style="align:left; width:430; height:82"&gt;
&amp;nbsp;&lt;p&gt;Question 2? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question2"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question2"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question2"&gt;Choice 3&lt;br&gt;
&lt;/div&gt;
&lt;div style="align:left; width:430; height:127"&gt;
&amp;nbsp;&lt;p&gt;Question 3? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question3"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question3"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question3"&gt;Choice 3&lt;br&gt;
&lt;/div&gt;
&lt;div style="align:left; width:430; height:127"&gt;
&amp;nbsp;&lt;p&gt;Question 4? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question4"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question4"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question4"&gt;Choice 3&lt;br&gt;
&lt;/div&gt;
&lt;div style="align:left; width:430; height:127"&gt;
&amp;nbsp;&lt;p&gt;Question 5? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question5"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question5"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question5"&gt;Choice 3&lt;br&gt;
&lt;/div&gt;
&lt;div style="align:left; width:430; height:127"&gt;
&amp;nbsp;&lt;p&gt;Question 6? &lt;br&gt;

&lt;INPUT type="radio" value="1" name="question6"&gt;Choice 1&lt;br&gt;
&lt;INPUT type="radio" value="2" name="question6"&gt;Choice 2&lt;br&gt;
&lt;INPUT type="radio" value="3" name="question6"&gt;Choice 3&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;INPUT type="button" Name="submit" onClick="submit_form(this.form)" value="OK"&gt;
&lt;INPUT type="reset" Name="reset" value="reset"&gt;
&lt;/div&gt;
&lt;INPUT type="text" Name=Total&gt;
&lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;


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...?
×

Success!

Help @hsloh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...