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
Solved

Radio Button

Posted on 1998-08-25
2
207 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get bootstrap element to collapse at wider screen width 3 41
Show Ruler in Outlook 2010 STILL NOT SHOWING! 4 22
Do alert on select 6 13
Javascript 2 17
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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…

790 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