...

View Full Version : Toggle action of a checkbox



bandruss
03-04-2005, 01:38 AM
Hi All,

I have a screen on which checkboxes are displayed dynamically. I do not have any control on how many would be there. The default label on the button is SELECT ALL. Once I click it all checkboxes are checked. The label at that point changes to UNSELECT ALL. If I click on the button now (UNSELECT ALL), all the checkboxes are unchecked. Following code accomplishes that funcationality.

However, I need to make a further enhancement to this code.

1. User clicks on SELECT ALL
2. All checkboxes are selected
3. User unchecks one or more of the boxes.
4. Label should not be SELECT ALL anymore.
(Since one or more checkboxes are unchecked)


Any help with this would be greatly appreciated.

Thank you,
William H. Andruss.


Here is the button syntax:
=========================

<TD>
<input type="button" class="ApScrnButton" onmouseover="if(!this.disabled){this.className='Ap
ScrnButtonHover';}"
onmouseout="if(!this.disabled){this.className='ApScrnButton';}" value="SELECT ALL" id="myButton1" onClick="javascript:changeAll()"></input>
</TD>

Here is the underlying javascript:
=================================

function changeAll() {
if (document.form.myButton1.value == "SELECT ALL") {
i = 0;
tmpstr = "";
count = document.form.elements.length;
while (i < count) {
tmpstr = document.form.elements.name.split("UserId_");
if (document.form.elements.type == "checkbox"
&& tmpstr.length == 2) {
document.form.elements.checked = true;
document.form.myButton1.value = "UNSELECT ALL";
}
i++;
}
}
else {
i = 0;
tmpstr = "";
count = document.form.elements.length;
while (i < count) {
tmpstr = document.form.elements.name.split("UserId_");
if (document.form.elements.type == "checkbox"
&& tmpstr.length == 2
&& document.form.elements.id != 1) {
document.form.elements.checked = false;
document.form.myButton1.value = "SELECT ALL";
}
i++;
}
}
}

codegoboom
03-04-2005, 11:07 AM
You need to assign an onclick event to each of the checkboxes (or one to their container), for sending (or getting) the "checked" property, so that the button is changed--if checked is false.

bandruss
03-16-2005, 09:42 PM
Thank you codegoboom. The problem is now resolved. Extremely sorry, I was not able to reply earlier. I had to be away on a family emergency and just returned. Thanks again.

codegoboom
03-17-2005, 01:32 AM
no sweat ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum