Help - trying to code Select All for checkbox array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leftcoast_mike
Forum Newbie
Posts: 3
Joined: Sun Feb 07, 2010 1:13 am

Help - trying to code Select All for checkbox array

Post by leftcoast_mike »

Hi there. This is my first post, most definitely won't be my last.

I'm rather new to php so please excuse me if this is kind of a noob question (I tried searching).

I have a messenger inbox that puts a checkbox next to each message. To delete them all you have to manually check each checkbox and then hit the submit button to delete.

I'm trying to code a "Select All" button that will select all of the checkboxes at once.

This is the existing code for the messenger form.

Code: Select all

$u2uheader
<form method="post" action="u2u.php?action=delete">
<table cellspacing="0" cellpadding="0" border="0" width="$tablewidth" align="center">
<tr> <td bgcolor="$bordercolor">
 
 
<table border="0" cellspacing="$borderwidth" cellpadding="$tablespace" width="100%">
<tr><td class="header" colspan="5" align="center">$lang_textu2uinbox</td></tr>
<tr>
<td class="header">$lang_textdeleteques</td>
<td class="header">$lang_textsubject</td>
<td class="header">$lang_textfrom</td>
<td class="header">$lang_textsent</td>
<td class="header">$lang_u2ureadstatus</td>
</tr>
$messages
</table>
</td></tr></table><br />
<input type="hidden" name="folder" value="$folder">
<input type="submit" name="alldel" value="$lang_textsubmitchanges">
 
</form>
$u2ufooter
This is a sample I've been working with that I thougth might work.

Code: Select all

<input type="button" name="Check_All" value="Check All"
onClick="CheckAll(document.myform.check_list)">
<input type="button" name="Un_CheckAll" value="Uncheck All"
onClick="UnCheckAll(document.myform.check_list)">

Thanks much for any help you may be able to offer :)
limitdesigns
Forum Commoner
Posts: 25
Joined: Sat Feb 06, 2010 9:05 pm

Re: Help - trying to code Select All for checkbox array

Post by limitdesigns »

This should probably go in the javascript forum.

But, as far as I know, there are no functions called "CheckAll" or "UncheckAll" that come with javascript. You're going to have to make them yourself, I'm afraid. Or, try searching online for somebody who has done that already.

If you're going to try yourself, I suggest naming the checkboxes "check1", "check2", "check3", etc, and then running through them with a for loop to get them all. But it could be easier if you just target them individually if there are only a few.

Example:

Code: Select all

 
var number_of_boxes = 10;
for(var i=1; i<=number_of_boxes; i++) {
    document.getElementById("check" + i).checked = TRUE;
}
 
Syntax may be off, but you get the gist of it.
Post Reply