Results 1 to 4 of 4

Thread: Checkboxes

  1. #1
    Join Date
    Jun 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkboxes

    Hi

    Checkboxes:

    I need a script that shows a layer when the checkbox is checked and hides a layer when the checkbox is unchecked.

    I've tried Dreamweaver's behavior functions but to no avail.

    Pls help!

    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    HTML Code:
    <input type="checkbox" onclick="if (this.checked) {document.getElementById('id1').style.visibility='visible'} else {document.getElementById('id1').style.visibility='hidden'};" />
    <div id="id1" style="visibility:hidden">Hi</div>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks!

    It works like a dream!

    Thanks Jon

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    HTML Code:
    <input type="checkbox" onclick="if (this.checked) {document.getElementById('id1').style.visibility='visible'} else {document.getElementById('id1').style.visibility='hidden'};" />
    <div id="id1" style="visibility:hidden">Hi</div>
    You could simplify that slightly using the conditional operator:

    Code:
    document.getElementById('id1').style.visibility = this.checked ? 'visible' : 'hidden';
    However, I'd use something more robust:

    Code:
    function setVisibility(object, visibility) {
      if(('string' == typeof object) && document.getElementById) {
        object = document.getElementById(object);
      }
      if(object && object.style) {
        object.style.visibility = visibility;
      }
    }
    
    setVisibility('id1', this.checked ? 'visible' : 'hidden');
    Mike

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
  •