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

Radio button

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi Guys!

Iam generating some radio buttons dynamically .

How to know how many radio buttons are there in the form.

for example i got 9 radio buttons (ie i know the total number).then i can go for the below code

(var i=0;i<9;i++)
{
if((document.form.r1.checked == true))
{
alert(&quot;something&quot;);
}
}

if i don't know the total numbers how to find the total numbers

help me guys....
[sig][/sig]
 
Try this...

Code:
<html>
<head>
</head>
<body>
<form name=frmForm id=frmForm>
 <input type=radio id=radTest name=radTest value=&quot;Radio 1&quot;> Radio 1<br>
 <input type=radio id=radTest name=radTest value=&quot;Radio 2&quot;> Radio 2<br>
 <input type=radio id=radTest name=radTest value=&quot;Radio 3&quot;> Radio 3<br>
 <input type=radio id=radTest name=radTest value=&quot;Radio 4&quot;> Radio 4<br>
 <input type=button id=btnTest name=btnTest value=&quot;Click Me&quot; onClick=&quot;fnCheck()&quot;>
</form>
</body>
</html>
<script language=&quot;javascript&quot;>
 function fnCheck(){
  var binFlag = false;
  var lenRad = document.frmForm.radTest.length - 1;
  for (var rad=0; rad<=lenRad; rad++){
   if (document.frmForm.radTest[rad].checked){
    alert(&quot;You checked choice number &quot; + document.frmForm.radTest[rad].value + &quot;.&quot;);
    binFlag = true
   }  
  }
  if (!binFlag) alert (&quot;You must check something!&quot;);
 }
</script>

-Rob [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top