Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select all checkbox and deselect all in just one button 2

Status
Not open for further replies.

Keendev

Technical User
Jan 23, 2006
106
PH
Hi,

I need to have a button that checks all the checkboxes,
and unchecks all checkboxes...
Similar to Select all and De-select all checkbox.

This is the code but doesn't really work. Maybe someone already did this kind functionality.
Code:
<script type="text/javascript">

function check_all(group, action)
{
 for (var i=0; i<group.length; i++)
  group[i].checked = action;
}

</script>

<form>

<INPUT type="button" name="checkall" 
value="Select all/Deselect all"  onClick="check_all( this.form['checkbox[]'], this.checked )">

<input type="checkbox" name="checkbox[]" value="$file">
<input type="checkbox" name="checkbox[]" value="$file">
<input type="checkbox" name="checkbox[]" value="$file">


</form>
Hope you can help me w/ this. Thanks in advance.


 
Under the condition that you insist of using that format of naming and setting values, do this.
> onClick="check_all( this.form['checkbox[]'], this.checked )"
[tt] onClick="check_all( this.form[red]([/red]'checkbox[]'[red])[/red], [red]true[/red] )"[/tt]
 
Correction
My mistake to revise the bracket. This is the amended version.
[tt] onClick="check_all( this.form[highlight][[/highlight]'checkbox[]'[highlight]][/highlight], [red]true[/red] )"[/tt]
 
Very nice tsuji ... I was able to use your suggestion successfully.

Thanks!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Hi,

i want to thank you for a big help =)


however how can i just use one button for that?


thnx
 
If you use onclick=... as suggested, you can use it within any standard object

Code:
<input name="button" type="button" onclick="..." />
<img src="theimage" ... onclick="..." />
<td onclick="..."></td>

It is up to you!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Quick and dirty? Have a global variable and change the value every time you call the function:
Code:
var isSelected = false;

function check_all(...) {
    if(isSelected) {
        // De-select all check boxes
    }else{
        // Select all check boxes
    }

    isSelected = !isSelected;
}

Or something like that...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top