Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toggle action of a checkbox

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

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    *this message will self destruct in n-seconds*

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no sweat
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •