Page 1 of 1

Help - trying to code Select All for checkbox array

Posted: Sun Feb 07, 2010 1:23 am
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 :)

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

Posted: Sun Feb 07, 2010 1:38 am
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.