SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change color of the text for the appropriatecheckboxes

    hi, i am not familiar with javascript: I am trying to change color of the text(for the appropriate check boxes).

    But This is not working after all check boxes are unchecked.

    For ex: when i uncheck all the check boxes and then check/uncheck the individual check boxes its working but after doing this if i check all the individual checkboxes using checkall the color of the text is changing properly.

    i know the reason why its not changing but i don't know how to proceed further.


    <script type="text/javascript">
    <!--

    function checkAll(checkname, exby) {
    for (i = 0; i < checkname.length; i++)
    {
    checkname[i].checked = exby.checked? true:false
    }
    if(exby.name="all")
    {
    if(exby.checked == false)
    document.getElementById("group").style.color = "red"
    else
    document.getElementById("group").style.color = "black"
    }

    }

    function check(sender) {
    if(!sender){ return; }
    var lblObj = document.getElementById(sender.id + "l");
    if(!lblObj){ return; }
    lblObj.style.color = !sender.checked ? 'red' : 'black';
    }
    // -->
    </script>
    <form name ="mylist">
    <input type="checkbox" name="all" checked onClick="checkAll(document.mylist.mylist1,this)">Check/Uncheck All<br>


    <div id="group">
    <input type="checkbox" name="mylist1" checked value="1" id="ch1" onclick="check(this)" /><label for="ch1" id="ch1l">Text1</label><br />
    <input type="checkbox" name="mylist1" checked value="2" id="ch2" onclick="check(this)" /><label for="ch2" id="ch2l">Text2</label><br />
    <input type="checkbox" name="mylist1" checked value="3" id="ch3" onclick="check(this)" /><label for="ch3" id="ch3l">Text3</label><br />
    <input type="checkbox" name="mylist1" checked value="4" id="ch4" onclick="check(this)" /><label for="ch4" id="ch4l">Text4</label><br />
    </div>
    </form>

    i hope you can understand the problem.thanks in advance for your patience
    thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Use checkname[i].click() instead.

    Code JavaScript:
    function checkAll(checkname, exby) {
      for (i = 0; i < checkname.length; i++)
      {
        if (checkname[i].checked != exby.checked) {
          checkname[i].click();
        }
      }
    }


Bookmarks

Posting Permissions

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