SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Select all - desellect all
-
Jul 4, 2004, 14:26 #1
- Join Date
- Dec 2002
- Location
- Manchester UK
- Posts
- 310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Select all - desellect all
I am sure this is a pretty easy thing to do for a javascript guru,
i have a select list, and want to select all options using a checkbox.
i have it working with 2 check boxes but how do i make it so that if the box is selected it selects all and deselected it deselects all.
I am posting the code i have that works so far, in case it helps.
Also being a php programmer i know nothing about js so you will really need to spell this out for me
HTML Code:function selectall() { aOptions = document.forms['f'].city.options; if(aOptions.length) { for(var i=0; i<aOptions.length; i++) aOptions[i].selected = 'selected'; } } function deselectall(){ aOptions = document.forms['f'].city.options; if(aOptions.length) { for(var i=0; i<aOptions.length; i++) aOptions[i].selected = false; } } <!-- and the checkboxes in question --> <input type="checkbox" name="selectall" value="selectall" onClick=selectall();> <input type="checkbox" name="deselectall" value="deselectall" onClick=deselectall();>
K-
-
Jul 4, 2004, 22:33 #2
- Join Date
- Jun 2004
- Location
- Dunedin
- Posts
- 17
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
do you mean to do this? i hope this helps
cheers
<html>
<head>
<script>
function CheckSelected() {
var s1 = document.getElementById("selectBox1");
if(s1.status == true){
selectall();
}else if(s1.status == false){
deselectall();
}
};
</script>
</head>
<!-- and the checkboxes in question -->
<input type="checkbox" id="selectBox1" value="selectall" onClick=CheckSelected();>
</html>
-
Jul 5, 2004, 01:53 #3
- Join Date
- May 2004
- Location
- Europe
- Posts
- 216
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Or all stuffed together:
Code:function selectDeselect(cbox) { var aOptions = document.forms['f'].city.options; for(var i=0; i<aOptions.length; i++) { aOptions[i].selected = cbox.checked; } }
Bookmarks