Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: radio buttons


Message #1 by joee@v... on Thu, 23 May 2002 14:09:52
Hi

Here is my soloution:

I made this function which returns a value or FALSE, if none selected.

function getRadioValue(oRadioElement) {
  var bHasSelectedOne =3D false;
  var i               =3D -1;
  var iLength         =3D oRadioElement.length;
  do {
    i++;
    bHasSelectedOne   =3D (oRadioElement[i].checked) ? oRadioElement[i]
.value
: false;
  } while ((!bHasSelectedOne) && (i<iLength));
  return (bHasSelectedOne);
}

You should send a Radio Element object - a reference to a group of radi
o
buttons.
For instance:
1 <input type=3D"radio" value=3D"1" id=3D"Radio2" name=3D"RadioGroup"> 
- 2 <input
type=3D"radio" value=3D"2    " id=3D"Radio1" name=3D"RadioGroup">

Here you would call it like this:
var selectedValue =3D getRadioValue(RadioGroup);
if (!selectedValue) {
  // Nothing selected
}

Cheers,

Sten Hougaard
EDB Gruppen
Application developer/web-designer
e-business solutions
Bredskifte All=E9 15
DK-8210 =C5rhus V
Tlf. +xx xx xx xx xx
Fax +xx xx xx xx xx
Mobil +xx xx xx xx xx
E-mail: stg@e...


                                                                       
                                           
                    joee@v...                                     
                                           
                    .com                 To:     "JavaScript HowTo" <ja
vascript_howto@p...>               
                                         cc:                           
                                           
                    23-05-2002           Subject:     [javascript_howto
] radio buttons                            
                    16:09                                              
                                           
                    Please respond                                     
                                           
                    to "JavaScript                                     
                                           
                    HowTo"                                             
                                           
                                                                       
                                           
                                                                       
                                           




Can someone show me where or how to write a function to see if a radio
button is checked. For example I have two radio buttons called premium,

one has a value of 'yes' and the other has a value of 'no'. Both radio
buttons are "turned off" when the page loads. The user must choose one.

How do I checkc to make sure one of the radio buttons was checked?

Thanks

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogra
mme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogra
mme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogra
mme
r-20





  Return to Index