Cannot access checkbox element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darran
    New Member
    • Feb 2007
    • 1

    Cannot access checkbox element

    I did a form, I created a checkbox under the same name 'lead_role' but I can't seem to access it in my javascript validation.

    This is the code in my HTML page
    <input name="lead_role " id="lead_role" type="checkbox" class="style30" value="1">

    And this is the validation I am testing out
    alert(document. form1.lead_role .checked);

    My browser returns me an 'undefined' alert message.

    The only way I was successful in accessing the element is using the getElementById( ) method but that only gets the very first instance of the checkbox.

    Can anyone help me out? Thanks :)
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    lead_role is an array of checkboxes, so loop through, e.g. the third checkbox checked value can be accessed by:
    Code:
    document.form1.lead_role[2].checked

    Comment

    Working...