
August 3rd, 2004, 03:35 PM
|
|
|
|
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152
Time spent in forums: < 1 sec
Reputation Power: 4
|
|
|
RE: If statement
OK, here is a script that I believe will do what you want...
Code:
<html>
<head>
<title>Page title</title>
<script type="text/javascript">
function SelectDeselectAll(objElement,objForm) {
for (i=0;i<objForm.length; i++){
if (objForm.elements[i].type=="checkbox") {
if (objForm.elements[i].name.substring(0,3)==objElement.name){
objForm.elements[i].checked=objElement.checked;
}
}
}
}
// -->
</script>
</head>
<body>
<form>
<input type="checkbox" name="negative_1"/>Negative 1 <input type="checkbox" name="positive_1"/>Positive 1<br>
<input type="checkbox" name="negative_2"/>Negative 2 <input type="checkbox" name="positive_2"/>Positive 2<br>
<input type="checkbox" name="negative_3"/>Negative 3 <input type="checkbox" name="positive_3"/>Positive 3<br><br />
<input type="checkbox" name="neg" onClick="SelectDeselectAll(this,this.form)"/>Check/Uncheck negative<br>
<input type="checkbox" name="pos" onClick="SelectDeselectAll(this,this.form)"/>Check/Uncheck positive
</form>
</body>
</html>
The only important thing to know is that the first three letters of the name of the checkboxes must
match the name of the checkbox that does the selection and deselection.
|