Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript headache

Options
  • 04-04-2002 2:20am
    #1
    Registered Users Posts: 2,660 ✭✭✭


    I have a form, which can have 0 or more checkboxes. When there are more than one the array attribut of the checkboxes work fine, when there is only one it doesnt. Can anyone explain why.

    I know its possible to have an array with only one element (in some languages, it might be different for javascript) so this is really doing my head in.

    please please please jim can you fix it for me to sleep in peace.


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Yeah you can have an array with only one element, are you looking at element[1] or element[0]?

    You can also test like this:
    var checkBoxes = document.myform.checkboxes;
    
    if (checkBoxes[1])   // there are at least two elements
    {
       for (i =0; i < checkBoxes.length; i++)
       {
          //whatever
       }
    }
    else
    {
       if (checkBoxes[0].checked)
       {
          // only one, and it's checked
       }
    }
    


Advertisement