SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    sitepoint forums
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP on PHP and Javascript

    hi,
    I need some help to figure this out. I hope you understand my english

    I have a form which includes a check box field. Each data displayed has it's own check box. And I also have one button that checks all check boxes.

    Now, This is my problem, I got some errors when trying to execute a javascript in php. Can somebody provide your help pls.?

    this is the javascript. no problem with this
    Code:
    echo "
        <script language=\"JavaScript\">
        <!--
          function checkAll(field){
            for(i = 0; i < field.length; i++){
              field[i].checked = true ;
            }
          }
          
          function uncheckAll(field){
            for(i = 0; i < field.length; i++){
              field[i].checked = false ;
            }
          }
        //-->
        </script> 
    ";

    this is the first part of the form that displays the datas with check boxes. no problem
    Code:
    while ($myrow = mysql_fetch_assoc($sql)) { 
        echo "<tr>";
        echo "<td>$myrow[ID]</td>";
        echo "<td>";
        echo "<input type=\"checkbox\" name=\"records_id[]\" value=\"$myrow[ID]\">"; 
        echo "</td>";
        $count +=1;
    }


    this is the other part of the form that includes the check all boxes. this is where the error occurs
    Code:
    echo "<td><tr>";
    echo "<input type=\"button\" value=\"Check all\" onClick=\"checkAll(document.chkboxForm.records_id[])\">";
    echo "<input type=\"button\" value=\"Uncheck all\" onClick=\"uncheckAll(document.chkboxForm.records_id[])\">";
    echo "<input type=\"submit\" value=\"submit\" name=\"submit\">";
    echo "</td></tr>";
    echo "</form>";

    the problem is the javascript cannot recognized the name of the check box which is

    records_id[]


    any opinion will be highly valued thanks very much.

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Instead of accessing the form property the OOP way, what you'll have to do is call it with this syntax using literal arrays:
    onclick="checkAll(document['chkboxForm']['records_id[]']);"

    This way the subscript resolves to a string. Try that out it should work!

    -xDev

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    sitepoint forums
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers xDev!
    thank you very much! it worked!

    thank you

  4. #4
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •