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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP, Loop, Check Boxes

  • 25-02-2011 10:32am
    #1
    Registered Users, Registered Users 2 Posts: 378 ✭✭


    Hi guys

    I would be greatfull with some help please

    I run an sql query, then in a while loop I ouput and create a table with one column of check boxes

    I then have a javascript function that I need to select all the checkboxes or uncheck them

    This funcation works if I only return one row in my while look, but any more than one row and the "select all" doesnt select anything

    I would be ever so greatfull for any help

    Here is the code:

    Javascript:

    <script type="text/javascript">
    <!--
    function checkall()
    {
    var df=document.InboxForm.elements;
    for(var i=0;i<df.length;i++)
    {
    //alert(df.name);
    df.checked=true;
    }
    }

    function uncheckall()
    {
    var df=document.InboxForm.elements;
    for(var i=0;i<df.length;i++)
    {
    //alert(df.name);
    df.checked=false;
    }
    }
    -->
    </script>


    While loop:

    while($row = mysql_fetch_array($result))
    {
    $subject=$row;
    $datesent=$row;
    $fromuser=$row;
    $from_firstname=$row;
    $from_lastname=$row;
    $id=$row;
    $read=$row;

    echo'





    <tr '.$RowColor.'>
    <td align="center"><form name="InboxForm"><input type="checkbox" name ="selected[]"></form></td>

    <td align="center" style="font-weight: '.$new.'; color:'.$new_color.';">'.$from_firstname.' '.$from_lastname.' ('.$fromuser.')</td>


    <td style="word-wrap: break-word; font-weight: '.$new.'; color:'.$new_color.';" align="center">'.$subject.'</td>
    <td align="center" style="font-weight: '.$new.'; color:'.$new_color.'";>'.$datesent.'</td>

    <td align="center" style="font-weight: '.$new.'; color:'.$new_color.';"><a href="view-message.php?id='.$id.'"><img src="images/view-message.png"></a></td></tr>';

    }


    Then call the function to check all the check boxes:

    echo '
    <a href="#" onclick="checkall(InboxForm);" title="Check all boxes">CheckAll</a>';



    Thanks in advance of any replies


Comments

  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    Firstly, did you alert the length that it's getting ?

    Then try giving each checkbox a unique ID - leaving the NAME as is

    Failing that, use jQuery - it'll do this with its eyes closed using one line of code.


  • Registered Users, Registered Users 2 Posts: 378 ✭✭bob2oo7


    Sorted with Jquery, thank you for the help


Advertisement