|
-
Jul 21st, 2008, 01:27 PM
#1
Thread Starter
Frenzied Member
Select and Deselect groups of checkboxes script
Hi,
I have seen many scripts for selecting and desselecting all checkboxes in a form. Does anyone know of a script ot how to make it do select only groups of checkboxes in a form?
What I mean by this is I'll have different sets of checkboxes in one form. And I want to select all or deselect them by their category. Maybe I can do it by looking at part of the name of each checkbox or something.
I don't know how to write the scripts so I'm just checking to see if someone has one.
Thanks anyways!
Warren
-
Jul 21st, 2008, 03:44 PM
#2
Fanatic Member
Re: Select and Deselect groups of checkboxes script
Hello WarrenW,
I am not sure how to write the script that you are looking for, however, I think that most sites use JavaScript to accomplish this effect and not ASP. I will look around to see if I can find an example.
-
Jul 22nd, 2008, 10:39 PM
#3
Hyperactive Member
Re: Select and Deselect groups of checkboxes script
Am not sure what you are looking for but here is what i understand ...
Use names of the check box simmilar for a group like for groups A which have 4 checkboxes ,all check boxes name start from A1 till A4 .. read them in a loop by concatinating A with loop count and mark them checked or unchecked
you can do it in either ASP or JAVA Script your choice
HTH
-
Jul 23rd, 2008, 09:30 AM
#4
Fanatic Member
Re: Select and Deselect groups of checkboxes script
Hi,
Here is a simple example of what I think you're trying to do using javascript.
Kirun is right you can do this with either javascript or vbscript/jscript, however he said ASP (which is serverside) but I'm sure he meant vbscript. I'm sure you know this but in case you don't - VBScript limits you to IE, so javascript is the language to use if you want to target multiple browsers.
Note: This was knocked up in a few minutes, could be done a lot better with with a bit more time. By this i mean using a technique known as "unobtrusive javascript"
Code:
<html>
<head>
<title>Check/UnCheck groups</title>
<script type="text/javascript">
function unCheckAll(grp){
var frm=document.forms["myFrm"];
for(var i=0;i<frm.length;i++){
current=frm.elements[i];
if(current.type==="checkbox" && current.name.indexOf(grp)!==-1){current.checked=false;}
}
}
function checkAll(grp){
var frm=document.forms["myFrm"];
for(var i=0;i<frm.length;i++){
current=frm.elements[i];
if(current.type==="checkbox" && current.name.indexOf(grp)!==-1){current.checked=true;}
}
}
function switchCheck(grp){
var frm=document.forms["myFrm"];
for(var i=0;i<frm.length;i++){
current=frm.elements[i];
if(current.type==="checkbox" && current.name.indexOf(grp)!==-1){
if(current.checked===true){
current.checked=false;
}else if(current.checked===false){
current.checked=true;
}
}
}
}
</script>
</head>
<body>
<form id="myFrm" action="" method="post">
<fieldset><legend>Group 1</legend>
<input type="button" name="btnCheckG1" id="btnCheckG1" value="Check All" onclick="checkAll('chkG1')">
<input type="button" name="btnUnCheckG1" id="btnUnCheckG1" value="Uncheck All" onclick="unCheckAll('chkG1')">
<input type="button" name="btnSwitchCheckG1" id="btnSwitchCheckG1" value="Switch All" onclick="switchCheck('chkG1')"><br>
<input type="checkbox" name="chkG1_1" id="chkG1_1" value="Whole"><label for="chkG1_1">Whole</label><br>
<input type="checkbox" name="chkG1_2" id="chkG1_2" value="Semi"><label for="chkG1_2">Semi</label><br>
<input type="checkbox" name="chkG1_3" id="chkG1_3" value="Skimmed"><label for="chkG1_3">Skimmed</label><br>
</fieldset>
<fieldset><legend>Group 2</legend>
<input type="button" name="btnCheckG2" id="btnCheckG2" value="Check All" onclick="checkAll('chkG2')">
<input type="button" name="btnUnCheckG2" id="btnUnCheckG2" value="Uncheck All" onclick="unCheckAll('chkG2')">
<input type="button" name="btnSwitchCheckG2" id="btnSwitchCheckG2" value="Switch All" onclick="switchCheck('chkG2')"><br>
<input type="checkbox" name="chkG2_1" id="chkG2_1" value="Mirror"><label for="chkG2_1">Mirror</label><br>
<input type="checkbox" name="chkG2_2" id="chkG2_2" value="DT"><label for="chkG2_2">Daily telegraph</label><br>
<input type="checkbox" name="chkG2_3" id="chkG2_3" value="Times"><label for="chkG2_3">Times</label><br>
<input type="checkbox" name="chkG2_4" id="chkG2_4" value="Observer"><label for="chkG2_4">Observer</label><br>
</fieldset>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit"><br>
</form>
</body>
</html>
-
Jul 25th, 2008, 11:43 PM
#5
Hyperactive Member
Re: Select and Deselect groups of checkboxes script
sorry for writing it ASP .. sure i meant VB script
Rate the post if it has helped you
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|