Solved

Radio Button

Posted on 1998-08-25
2
204 Views
Last Modified: 2010-04-09
Dear Experts,
   I have 3 radio buttons on my page, which belong to the group rdoButtons.  They are named as follows..
First name = rdoFirstName
Last Name = rdoLastName
Both  = rdoBoth
My question to you, is how to dynamicly read which one is filled and display a number (ex: rdoFirstName = 1, rdoLastName = 2, rdoBoth = 0) on the page.  I need this asap.
Thanks,
Treason
0
Comment
Question by:TrEaSoN
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
Bluemoon earned 50 total points
ID: 1837015
This can be done very simple, i made a little example for you to test...

<HTML><SCRIPT>
function dread()
{
 var i, val;
 val = -1; // no radiobutton checked...

 for(i=0;i<document.form.rdoButtons.length;i++)
      {  if (document.form.rdoButtons[i].checked)            
                    val=document.form.rdoButtons[i].value;
              }

 alert("readout = "+val);
}

</SCRIPT><BODY>

<FORM NAME=form>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=1>First name<BR>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=2>Last name<BR>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=0>Both<BR>
<INPUT TYPE=BUTTON Onclick="dread()" VALUE="readout">
</FORM>
</BODY></HTML>

Greetings Bluemoon
0
 
LVL 1

Expert Comment

by:Bluemoon
ID: 1837016
On second thought, you'd probebly like to keep the 'values' , hmm try this instead:

<HTML>

<SCRIPT>
function dread()
{
 var val;
 
 if (document.form.rdoButtons[0].checked) val=1;
 else if (document.form.rdoButtons[1].checked) val=2;
 else if (document.form.rdoButtons[2].checked) val=0;
 else val = -1;
 
 alert("readout = "+val);
}

</SCRIPT><BODY>

<FORM NAME=form>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=rdoFirst>First name<BR>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=rdoLast>Last name<BR>
<INPUT TYPE=RADIO NAME=rdoButtons VALUE=rdoBoth>Both<BR>
<INPUT TYPE=BUTTON Onclick="dread()" VALUE="readout">
</FORM>

Bluemoon
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now