Solved

Radio Button

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JavaScript communication inside a IFRAME 9 48
Syntax Error 6 32
Condidional <a href = ....> 1 25
Windows 10 bookmarks html file 6 30
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

760 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

21 Experts available now in Live!

Get 1:1 Help Now