Check if radio button is checked

Giganews Newsgroups
Subject: Check if radio button is checked
Posted by:  Vancouver (minghui…@gmail.com)
Date: Wed, 12 Mar 2008

Hi there,

I have 24 radio button groups, and 7 options for each group. I wrote
code below trying to see if each radio button group is checked. But it
does not work. Any help? Thanks.

(24 radio button groups are named question[0] to question[23].
choices[] is to store true/false)

<script type="text/JavaScript">
function ifChecked()
{
    var choices=new Array();

    for (index=0;index<24;index++)
    {
        choices[index]=false;
        for (i=0;i<7;i++)
        {
            if (document.forms[0].question[index][i].checked)
                        {
                choices[index]=true;
                break;
            }

                }
    }
    for (index=0;index<24;index++)
        {
        if (!choices[index])
                          {
                  alert ("Please make a selection");
                return false;
              }
        }
    return true;
}
</script>

Replies