467,892 Members | 1,877 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,892 developers. It's quick & easy.

radiobutton values in JS?

hi... i cant seem to get value of set of radio buttons thru javscripting.. i hv set values to the radiobuttons but cannot retrieve them or calculate them in JS although it looks simple. do i need to convert the values to numeric in JS.. pls help me I am stuck..i hv pasted the code below:


********************************

[HTML]<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Do you have a rich mindset</title>

<script type="text/javascript">
function display(frm)
{
var val=0
var message =" Your final score is :\n\n "
for(var i=0;i<=r1[i].length;i++)
if (frm.r1[i].checked
{
val=val+frm.r1[i].value
}
for(var i=0;i<=r2[i].length;i++)
if (frm.r2[i].checked
{
val=val+frm.r2[i].value
}
for(var i=0;i<=r3[i].length;i++)
if (frm.r3[i].checked
{
val=val+frm.r3[i].value
}
for(var i=0;i<=r4[i].length;i++)
if (frm.r4[i].checked
{
val=val+frm.r4[i].value
}
for(var i=0;i<=r5[i].length;i++)
if (frm.r5[i].checked
{
val=val+frm.r5[i].value
}
message= message + val
alert(message)

</script>


</head>

<body>
<form name=Form1>
</form>
<p>&nbsp;</p>
<p><font color="#003399"><b><span style="FONT-SIZE: 14px; LINE-HEIGHT: 18px">
<font face="Verdana" color="#ff0000" size="4">Do you have a rich mindset?</font></span></b></p>
<ul>
<li><b><font face="Verdana" color="#3333ff" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">A customer comes just before
closing time.</span></font></b></li>
</ul>
<b><font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
<p style="COLOR: #000000; LINE-HEIGHT: 0px"><br>
&nbsp;</p>
</span></font></b>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r1" VALUE=2> Do you attend to him willingly?</div>
</span></font>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r1" VALUE=1></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">D</span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">o
you attend to him grudgingly?</div>
</span></font>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r1" VALUE=0></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do you ask him to come
the next day?<br>
&nbsp;</div>

</span></font><font size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
<ul>
<!-- CHECKING RADIO BUTTONS !-->
<li></span></font>&nbsp;<font color="#3333ff"><b><font face="Verdana" size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">A
business meeting coincides with your childís birthday party.</span></font></b></font><b><font face="Verdana" color="#000000" size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px"></li>
</ul>
</span></font></b>
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r2" VALUE=1> Do you finish the meeting and
join the party late?</span></font><div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r2" VALUE=2>Do you
apologize to your
child and have another party?</span></font>

</div>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r2" VALUE=0>Do you cancel the business
meeting?</span></font><font size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px"><ul>
<!-- CHECKING RADIO BUTTONS !-->
<li></span></font>&nbsp;<font color="#3333ff"><b><font face="Verdana" size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">A
customer keeps you waiting in his office.</span></font></b></font></li>
</ul>
<p>
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r3" VALUE=0>
</span>
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
Do you get frustrated and
angry?</span></font>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r3" VALUE=1></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do you read a magazine
calmly?</span></font>&nbsp;

</div>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r3" VALUE=2></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do you make calls related to
office work?</span></font></div>

</div>

<ul>
<li>
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;</span></font>
<font color="#3333ff"><b><font face="Verdana" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">You have only two out of four
skills required for your job.</span></font></b></font></li>
</ul>
<p>
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r4" VALUE=2> Do you put in efforts to
learn the other skills?</span></font>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r4" VALUE=1></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do
you somehow manage?</span></font> &nbsp;

</div>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r4" VALUE=0>D</span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">o you look for another job?</span></font></div>

<ul>
<li>
<b><font face="Verdana" color="#3333ff" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Your boss is away on a
business trip.</span></font><font face="Verdana" color="#000000" size="2"><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px"></li>
</span></font></b>
</li>
</ul>
<p>
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r5" VALUE=1>
</span>
</font></font><font face="Verdana" style="font-size: 12px">Do you work as usual?</font><font color="#003399"><div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r5" VALUE=2></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do you work more?</span></font></div>
<div style="FONT-SIZE: 12px; COLOR: #000000; LINE-HEIGHT: 0px; FONT-FAMILY: Verdana">
<font face="Verdana" color="#000000" size="2">
<span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="r5" VALUE=0></span><span style="FONT-SIZE: 12px; LINE-HEIGHT: 16px">Do
you come late or leave early?</span></font><p>&nbsp;</p>

<p></p>
<p></p>


<p align="center">&nbsp;<input type="submit" align= "center" id= "submit" value="VIEW RESULT!" onClick="display(this.form)"></p>
</p>
</form>
</body>
</html>[/HTML]


***************************i cant seem to use document.write the radio button value either!! i need to add the values of selected radio buttons in each category and give a final score.Kindly help.......
renji
Apr 17 '07 #1
  • viewed: 1645
Share:
1 Reply
acoder
Expert Mod 8TB
Welcome to TSDN.

You've closed your form tag straight after the opening tag.

Also, in your code,
Expand|Select|Wrap|Line Numbers
  1. if (frm.r1[i].checked
should have an ending brace:
Expand|Select|Wrap|Line Numbers
  1. if (frm.r1[i].checked)
If you have any more problems, post again.
Apr 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by VK | last post: by
11 posts views Thread by William Gill | last post: by
2 posts views Thread by Sascha | last post: by
reply views Thread by dfetrow410 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.