Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple radiobutton validation please :) 1

Status
Not open for further replies.

Guy999

Programmer
Apr 1, 2002
27
GB
Hi

I'm trying to validate a radio button which has no default value because I want to make sure the user chooses one of two options.

I want to use simple validation like I'd use on a text field, but this doesn't work for a radiobutton

e.g.

if (document.form1.radiobuttonx.value.length < 1) {
alert(&quot;please choose&quot;);
return false;
}

Thanks
Guy
 
if both radio buttons are named the same, use this:

if (!document.form1.radiobuttonx[0].checked &&
!document.form1.radiobuttonx[1].checked) {
alert(&quot;please choose&quot;);
return false;
} =========================================================
if (!succeed) try();
-jeff
 
How do you get the value of a checked button?
example:
poor
ok
not so bad
average
slightly above average
pretty good
awesome

radiobuttonselection = //what goes here to get the value?

alert(radiobuttonselection) How many software developers does it take to change a light bulb?
None: it works in everyone else’s office, it must work in yours too.
 
bombboy,

simply by asking for it, provided you've defined it:

<input type=&quot;radio&quot; name=&quot;radio1&quot; value=&quot;radio1value&quot; />

note, however, that the way radio buttons are intended to work is to report a state of &quot;checked&quot; or not &quot;checked&quot;. if you define a value for a radio button, it will report that &quot;value&quot; whether it is checked or not.

=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top