?
Solved

Radio Button

Posted on 1998-08-25
2
Medium Priority
?
212 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

765 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