#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    29
    Rep Power
    0

    Javascript problem! How to use "[]"?


    Hi!

    I want to use some Javascript, but there is a problem:
    How can I refer to an array in the HTML page?

    document.myform.listofsomething[1].checked -or-
    document.myform.listofsomething.1.checked

    Doesn't work!

    I want to get the status of some checkboxes (true or false)
    In the HTML page it's like this:

    <input type="checkbox" name="listofsomething[0]" value="78">
    <input type="checkbox" name="listofsomething[1]" value="63">
    <input type="checkbox" name="listofsomething[2]" value="99">

    Is it neccesary to use number between the "[ ]"? PHP accepts the variable (array) without numbers, but does Javascript do so?

    Who knows the answers? Thanks!

    Max
    Last edited by hopsakee; October 9th, 2001 at 04:25 PM.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    25
    Could you not just give each one a name such as

    something1
    something2
    something3

    then collect the status of them using a for loop and an eval statement?


  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    29
    Rep Power
    0
    No...since i want PHP to treat these variables as an array. But the solution came... document.myform.elements["mycheckbox[2]"].checked

    Something like this...

IMN logo majestic logo threadwatch logo seochat tools logo