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

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0

    javascript function


    I have a form containing 1 submit button, and 3 checkboxes (name: select[0],select[1],select[2],) and the form (name: check_form)

    my submit is labled
    <input type="submit" name="delete" value="Delete" onClick="funct()">

    inside the function i have

    function funct()
    {
    //i wish to add a hidden in here based on which checkboxes were checked.
    for(i=0;i<3;i++)
    {
    if(document.check_form.select[i].checked == true)
    {
    document.write('<input type="hidden" name="add_hidden[i]" value="yes">');
    }
    }

    }

    the problem is that it says that document.check_form.select[i] is null or not an object even though it is an object and works fine in another function. what am i doing wrong?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0

    Angry nevermind


    i fixed it myself
    all is well
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0

    BTW


    in case you want to know how i fixed it.
    i went around the problem.
    since im useing PHP with it, i named the checkbox "check[$t]"
    but javascript didnt except the fact the i named it an array without proper array initializing so i used instead the form index.

    i had
    document.this_form.check[$t].checked but that came up with an error
    so i used instead
    document.this_form[$t+2]
    i used the +2 because what i wanted started with the 3rd object in the form and continued for an indefinite amount of time.

    im just glad its over
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Your problem was because of how you used your input names in the javascript coupled with you having [] in your input names.

    In javascript, the [] sequence is an operator, so the statement,
    Code:
    document.check_form.select[i]
    will look for the i index of the object document.check_form.select. But, in your source, select is not an array, let alone defined. Also, in some browsers, document.check_form may not evaluate properly either, you should use document.forms.check_form.

    If you want to keep the [] in the names, you need to use the following pointers in javascript&#58;
    Code:
    document.forms.check_form['select[1]']
    In this case, the name select[1] is being treated as a string, and the [] operator isn't being interperted by the scripting engine.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    14
    Rep Power
    0

    Thumbs up thanks


    thanks for the help

IMN logo majestic logo threadwatch logo seochat tools logo