#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171

    If checkbox "just got checked" do this


    Hi;

    I want to show or hide an element based on a checkbox.

    SO if checkbox got checked, show the element, if it got unchecked, hide it. I thought this would do it but it didn't!


    javascript Code:
      $('#customer_service_check_box').click(function () {
          if (this.checked) {
              $("#customer_service").show();
          } else {
              $("#customer_service").hide();
          }
      })
    What should I change?

    Thanks
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,187
    Rep Power
    184
    Take a look at the :checked Selector; I think that will help you out with this.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    Originally Posted by web_loone08
    Take a look at the :checked Selector; I think that will help you out with this.
    Not really. Please give me a bit more help.

    Thanks

    This doent work either!
    javascript Code:
    $('#customer_service_check_box').click(function () {
        $("#customer_service").toggle(this.checked);
    });
    Last edited by English Breakfast Tea; December 31st, 2013 at 12:11 AM.
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,187
    Rep Power
    184
    Look at the :checked Selector and the :not() Selector. You combine the two of these APIs; to get the effect your looking for.
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    Sorry I forgot $( document ).ready(function()

    Its working now.

    Thank you

IMN logo majestic logo threadwatch logo seochat tools logo