C
calzephyr
Hi group,
I'm trying to modify a checkbox script. Currently it will select all
or deselect all. What we would like it to do now is reverse the
selection, so that the boxes that were checked become unchecked, and
vice versa. It's been a long time since I had to modify JavaScript and
I'm a little stuck. Here is the script below - the function I'm trying
to create is called inverseAll.
Thanks in advance,
Christine
<script language="JavaScript" type="text/javascript">
<!--
function setCheckAll(checkedState) {
var formElements = document.forms[0].elements;
var elementCount = formElements.length;
for(var i=0; i<elementCount; i++) {
var control = formElements;
if (control != null) {
if (control.type != null) {
if (control.type == "checkbox") {
control.checked = checkedState;
}
}
}
}
}
function checkAll() {
setCheckAll(true);
}
function uncheckAll() {
setCheckAll(false);
}
function inverseAll() {
//if setCheck equals true, uncheck
//if setCheck equals false, check
control.checked = !control.checked;
}
// -->
</script>
I'm trying to modify a checkbox script. Currently it will select all
or deselect all. What we would like it to do now is reverse the
selection, so that the boxes that were checked become unchecked, and
vice versa. It's been a long time since I had to modify JavaScript and
I'm a little stuck. Here is the script below - the function I'm trying
to create is called inverseAll.
Thanks in advance,
Christine
<script language="JavaScript" type="text/javascript">
<!--
function setCheckAll(checkedState) {
var formElements = document.forms[0].elements;
var elementCount = formElements.length;
for(var i=0; i<elementCount; i++) {
var control = formElements;
if (control != null) {
if (control.type != null) {
if (control.type == "checkbox") {
control.checked = checkedState;
}
}
}
}
}
function checkAll() {
setCheckAll(true);
}
function uncheckAll() {
setCheckAll(false);
}
function inverseAll() {
//if setCheck equals true, uncheck
//if setCheck equals false, check
control.checked = !control.checked;
}
// -->
</script>