problem validating checkbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter B. Ensch

    problem validating checkbox

    Can anyone explain why this code fails when the set of checkboxes
    consists of only one.

    myForm.update.l ength returns 0 instead of 1 with the result that
    I get an alert box even tho' the one checkbox is checked.

    Thanks,
    P


    function checkForm(myFor m) {
    var numBoxes = 1*myForm.update .length || 0;
    for(i=0;i<numBo xes;i++) {
    if(myForm.updat e[i].checked == true)
    return true;
    }
    alert("Select one or more part components to update");
    return false;
    }
    }

  • Peter B. Ensch

    #2
    Re: problem validating checkbox - errata

    Peter B. Ensch wrote:
    [color=blue]
    > Can anyone explain why this code fails when the set of checkboxes
    > consists of only one.
    >
    > myForm.update.l ength returns 0 instead of 1 with the result that
    > I get an alert box even tho' the one checkbox is checked.
    >
    > Thanks,
    > P
    >
    >[/color]

    My apologies. A bad cut&paste led to an error in my code
    example. It should have read:

    function checkForm(myFor m) {
    var numBoxes = 1*myForm.update .length || 0;
    for(i=0;i<numBo xes;i++) {
    if(myForm.updat e[i].checked == true)
    return true;
    }
    alert("Select one or more part components to update");
    return false;
    }


    Comment

    Working...