[thelist] Changing Check Box values with JavaScript

Keith Davis cache at dowebs.com
Fri May 25 23:20:00 CDT 2001


"Shaun M. Anderson" wrote:

> 
> function checkChoice(Form, i)
> {
> var NumOfFields;
> var FieldName;
> var NameLength;
> 
>         NumOfFields = document.Form.elements.length;
>         for (i=0; i <= NumOfFields; i++)
>         {
>         i = 18;
>         FieldName = Form[i].name;
>         NameLength = FieldName.length;
>                 if (FieldName.substring((5, NameLength - 6)) == "!check")
>                 {
>                         if (!Form[i].checked)
>                         {
>                                 Form[i].checked = true;
>                                 Form[i].value = "NOTCHECKED";
>                         }
>                 }
>         }
> }

Looks to me like you're on the right track plan wise. I think you're
just trying to make it harder than it is. This will do it:

function checkChoice(Form)
{
 for (i=0; i < Form.elements.length; ++i)
 {
   if (Form.elements[i].type == "checkbox")
   {
     if (Form.elements[i].checked == false)
       {
        Form.elements[i].checked = true;
        Form.elements[i].value = "NOTCHECKED";
       }
   }
 }
}

keith




More information about the thelist mailing list