problem in validating checkboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhuriks
    New Member
    • Jun 2010
    • 149

    problem in validating checkboxes

    hi,
    in my project i used jsp form..if i enter the values it should be added in XML file..i used check boxes in my form..if i select more than one it is not updating in the XML file...can anyone help me out...here is the code...

    Code:
    test.form
    
    <input type="checkbox" name="colors[]" value="blue" id="blue">Blue <br>
    <input type="checkbox" name="colors[]" value="red" id="red">red <br>
    <input type="checkbox" name="colors[]" value="green" id="green">green <br>
    Code:
    function validate()
    {
    var chks = document.getElementsByName('colors[]');
    var hasChecked = false;
    for (var i = 0; i < chks.length; i++)
    {
    if (chks[i].checked)
    {
    hasChecked = true;
    break;
    }
    }
    if (hasChecked == false)
    {
    alert("Please select at least one.");
    return false;
    }
    return true;
    }
    thanks in advance,
    madhu.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if i enter the values it should be added in XML file
    I don’t see, where you do that. you have posted a validation function, that tells, whether no checkbox is checked ot not.

    Comment

    • madhuriks
      New Member
      • Jun 2010
      • 149

      #3
      hi,
      i got the answer...

      Comment

      Working...