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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically validate radios

Status
Not open for further replies.

jerschab

Programmer
Apr 17, 2001
10
US
IDEA: I have a form that must have a radio box checked in each pair (3 pairs) as yes or no. If neither is choosen, I must alert and return flase (or something) for user to make sure to check one. I want to do this dynamically (as possible) so I create an array of the names of the radio buttons and would like to eventually go through a loop to do the checking for each ".checked" state. By hard coding the positions to choose in the array I find a definate problem - the strings in the array are not acceptable as objects in the "document.forms[0].(radio name)[0].checked" statement. How do I get around this? Can I? Hard coding the whole thing is very bulky...

CODE: (note, this is just to get it working on a small scale)

function checkRadio(){
var radios= new Array("PC_Ready","PBX_Ready","CABLE_Ready");
/*(i=0, i<2, i++);*/

if (document.forms[0].radios[1][1].checked ==false ){
alert(radios[1]+&quot; not checked&quot;)
}}
 
Try this:
Code:
if (eval(&quot;document.forms[0].&quot;+radios[1]+&quot;[1].checked&quot;) ==false ){
alert(radios[1]+&quot; not checked&quot;)
}

Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top