473,472 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

radiobutton values in JS?

1 New Member
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
1 1826
acoder
16,027 Recognized Expert Moderator MVP
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

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

Similar topics

8
by: VK | last post by:
Hi! What I'm missing in following code? Cannot get the values of radiobuttons. Starting only one class (GetVariant), it works. When I put two classes together, it doesn't. Regards, VK from...
11
by: William Gill | last post by:
I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep references to them in a 2 dimensional list ( rBtns ). It works fine, and I can even make it so only one button per column can be...
3
by: sofie | last post by:
Hello all, I use the following javascript function in a html document to set the level of one of eight available radiobuttons. The line that's commented out works fine under IE, but I need to...
2
by: Sascha | last post by:
hello ng i have a group of 6 radiobuttons with different values. when i check a radiobutton, i have to calculate something with the value of the new ckecked radiobutton. can please someone...
0
by: dfetrow410 | last post by:
I am using a datalist. I need to retrieve only selected values. I tried to use the following code below with no luck. Not sure how to do the backend <tr> <td align="left" valign="top"><img...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.