codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  toggle action of a button  bandruss at 00:20 on Friday, March 04, 2005
 

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++;
}
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Need help creating a Floating/follow menu
•  installing codes and compiler ..
•  Re: open excel file in html page
•  problem in radio button list
•  need javascript coding!
•  Can any one provide me the Code for uploading image, video& text files uising jsp
•  Re: Storing data from HTML to Excel or TXT
•  Intranet Blog Software
•  Memory Leak in ASP: Shared Memory Provider: The handle is invalid.


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009