[Javascript] How do you cycle thru the radio buttons on a webform ?

Roger Roelofs rer at datacompusa.com
Wed Jun 2 07:20:46 CDT 2004


Sometimes we get too close to our code :).  You need to add a line  
assigning to your obj variable.

On Jun 1, 2004, at 5:11 PM, <dev at qroute.net> wrote:

> I got this script so far, but cannot read the length of the radio  
> objects
>
   var CurRadioChecked, obj, z, x;
> for(z = 0; z < window.document.frmSurvey.length; z++) {
>  if ( window.document.frmSurvey[z].type == 'radio' ) {
>   CurRadioChecked=false
    obj = document.frmSurvey[z];
>
> // 
> ======================================================================= 
> ==
>   //
>   // on the following line obj.length comes as undefined and I cannot  
> run
> the for X loop/
>   //
>
> // 
> ======================================================================= 
> ==
>
>   for(x = 0; x < obj.length; x++){
>    if (window.document.obj[x].checked)
>    {
>     CurRadioChecked= true;
>     break;
>    }
>   }
>   if (CurRadioChecked)
>   {
>    //goto the next radio items this one is clear !...
>   }
>   else
>   {
>    alert('You must respond to all the required items. ' + obj.name + '  
> not
> responded.')
>    break;
>   }
>  }
>  else
>  {
>   //alert('non radio')
>  }
> }
>




More information about the Javascript mailing list