views:

747

answers:

2

Hi,

I currently have a report with pagination, that displays 10 records Per page.

Within this report, I also have a checkbox column for every record. Based on this,

I want to incorporate a "Check All" feature, so based on my scenario which displays 10 records, when I press the "Check All" checkbox, I would like to check all the visible records(10 at a time) in that page(pageno=3) and after deleting those 10 records, the page should be redirected to the same page(filename.php) with same page number(pageno=3).

www.mysite.com/filename.php?pageno=3

Plz... need help in this.

Regards, Adithya.B [email protected]

A: 

This could be solved using Javascript. How do you define the names of the checkboxes?

You could do a for loop to change the status of all checkboxes that are shown at the moment.

If you're using a javascript toolkit/framework like jQuery this is very easy. For instance you could give the class .page-[NUM] to all the checkboxes on a page and then use:

$(".page-[NUM]").each(function()
{
this.checked = checked_status;
});

Or if you use the same name for each checkbox on a page, try:

$("input[@name=thename]").each(function()
{
this.checked = checked_status;
});

where "thename" would be the name of your checkboxes on that page.

gernberg
please see my code once...
+1  A: 

Using some framework like jQuery will make your life a lot easier. Suppose following is structure of your records:

<table id="report">
    <tr><td> <input type="checkbox" id="tr1" /></td><td>..</td><td>...</td></tr>
    <tr><td> <input type="checkbox" id="tr2" /></td><td>..</td><td>...</td></tr>
    <tr><td> <input type="checkbox" id="tr3" /></td><td>..</td><td>...</td></tr>
    <tr><td> <input type="checkbox" id="tr4" /></td><td>..</td><td>...</td></tr>
    <tr><td> <input type="checkbox" id="tr5" /></td><td>..</td><td>...</td></tr>
</table>

<input type="checkbox" id="chkAll"/> Select All.

The following code (using jquery) will do the needful:

<script type="text/javascript">
    $(document).ready(function(){
        $("#chkAll").change(function(){
            if($("#chkAll").is(":checked")){
                $("#report tr td:first-child").find("input:checkbox")
                        .attr("checked","checked");
            }else{
                $("#report tr td:first-child").find("input:checkbox")
                       .attr("checked","");
            }
        });
    });
</script>

EDIT:- based on your code, try replacing your *boxes_checkall* function with this code;

function boxes_checkall(a,b) { var cbs=a.getElementsByTagName('input');

        for(var i=0;i<cbs.length;i++)
        {
           if(cbs[i].type.toLowerCase()=='checkbox')
           {
               cbs[i].checked = b==1;
           }
        }
   }
</script>
TheVillageIdiot
my code<?phpif (isset($_GET['pageno'])) { $pageno = $_GET['pageno'];} else { $pageno = 1; } $query = "SELECT count(*) FROM campaigns WHERE user_id='$user_id' and delete_flag=0";$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);$query_data = mysql_fetch_row($result);$numrows = $query_data[0];$rows_per_page = 10;$lastpage = ceil($numrows/$rows_per_page);$pageno = (int)$pageno;if ($pageno > $lastpage) { $pageno = $lastpage;} if ($pageno < 1) { $pageno = 1;} $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$selQuery = "SELECT * FROM campaigns WHERE user_id='$user_id' and delete_flag=0 $limit";?><td><input type="checkbox" name="delete[]" value="<?php echo $row['id'];?>" /></td><td><?php echo $cname; ?></td><?phpif ($pageno == 1) {echo "PREV";} else {$prevpage = $pageno-1;echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a>";} echo "( Page $pageno of $lastpage )";if ($pageno == $lastpage) {echo "NEXT";} else {$nextpage = $pageno+1;echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";}?>
<a href="javascript:void(null);" id="checkall" onclick="boxes_checkall(document.getElementById('form_1'),1);"> </a><a href="javascript:void(null);" id="uncheckall" onclick="boxes_checkall(document.getElementById('form_1'),0);"> </a><input type="image" name="delete" id="delete-btn" alt='delimg' src='images/delete.jpg' onmouseover='deleteOver()' onmouseout='deleteOut()'/>
Thats my code and pagination works well. But check all not working...If I remove pagination code, then check all is working. I can't understand where I'm going wrong...Well thanks in adv....
you can post code in question itself where can be formatted.
TheVillageIdiot