Solved

Radio Button

Posted on 1998-08-25
2
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

705 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