Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Member UNarmed's Avatar
    Join Date
    Sep 2008
    Posts
    90
    Member #
    17377
    My javascript knowlage is very limited so i was wondering whether anyone could help me.

    How would i go about hiding a div that has a certain class when a checkbox with a certain ID is ticked?

    Also i cant add any javascript to the checkbox input field so it has to be singled out by its ID. Naturally when the checkbox is not ticked the div in question has to be visible.

    Much thanks!

  2.  

  3. #2
    Junior Member
    Join Date
    May 2010
    Location
    Tampa, Florida
    Posts
    25
    Member #
    21994
    use this attribute in the check box's tag: onclick="javascript:swvis('id');" (replace 'id' with the id of the div you're hiding.)

    after that, add this javascript code:
    Code:
    function swvis(this)
    {
      var that = document.getElementById(this);
      if(that.style.visibility != "hidden"){
        that.style.visibility = "hidden";
      }else{
        that.style.visibility = "visible";
      }
    }
    Untested, hope this helps.

  4. #3
    Member UNarmed's Avatar
    Join Date
    Sep 2008
    Posts
    90
    Member #
    17377
    Thanks for that, the only problem is i cant add onclick to the input field =/ is there any other way to do this though?

  5. #4
    Junior Member
    Join Date
    May 2010
    Location
    Tampa, Florida
    Posts
    25
    Member #
    21994
    You should be able to. Why can't you?

  6. #5
    Member UNarmed's Avatar
    Join Date
    Sep 2008
    Posts
    90
    Member #
    17377
    Its a drupal site and i cant hardcode it in there. I would have gone about it the way you suggested but its not possible in this case.

  7. #6
    WDF Staff MikeB's Avatar
    Join Date
    Jun 2010
    Location
    Lincolnshire, UK
    Posts
    88
    Member #
    22274
    Does it have to be plain javascript or is jQuery available?

    I know this is possible via jQuery as I've done similar things before but never done it in plain javascript.
    Mike Barlow
    WDF Co-Owner

    Need help? PM Me!

  8. #7
    Member UNarmed's Avatar
    Join Date
    Sep 2008
    Posts
    90
    Member #
    17377
    Hey yup i ended up using jquery to get the job done =]

    Check the below link if you need something similare http://iamzed.com/2006/12/14/using-j...box-selection/

    Thanks for the help one again guys!

  9. #8
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Location
    Las Vegas
    Posts
    128
    Member #
    15503
    I'm a little late to help but thought I'd put some code in here to show people how to do this:

    with jQuery:
    Code:
    $(document).ready(function(){
      $("#myCheckbox").click(function(){
        $("#myDivId").hide();
      });
    });
    without jQuery (not as fun but good to know):
    Code:
    window.onload = function(){
      var myCheck = document.getElementById("myCheckbox");
      var myDiv = document.getElementById("myDiv");
      
      myCheck.onclick = function(){
        myDiv.style.display = "none";
      };
    };


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:29 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com