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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Suppressing/hiding content with checkboxes queries

    hey peeps, I have requirement when user can select different terms and condition, and if use check on one, the related T&C should show. I have this working but it seems that the location of the content is fixed. my code is per below

    Code:
    <U><B>Terms and conditions</b></u>
    <li><input type="checkbox" onclick="document.getElementById('info_terms1').style.visibility = this.checked ? 'visible' : 'hidden'"> Terms1<br>
    <li><input type="checkbox" onclick="document.getElementById('info_terms2').style.visibility = this.checked ? 'visible' : 'hidden'"> Terms2<br>
    
    <br>
    <div id="info_terms1" style="visibility:hidden"> terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    
    </div>
    
    <div id="info_terms2" style="visibility:hidden"> 
    terms2 condition <P>
    terms2 condition <P>
    terms2 condition <P>
    terms2 condition <P>
    </div>
    1) It seems that the DIVs location is fixed. If I checked on terms2 only, the content of terms2 seems to be at the bottom. Therefore it seems fixed. Is there a way that terms2 can be at the top if it's checked and terms1 is not?

    2) How do we default to checked?

    Many thanks!!!

    Cheers

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Play with the display property, instead of the visibility property:
    Code:
    <U><B>Terms and conditions</b></u>
    <li><input type="checkbox" onclick="document.getElementById('info_terms1').style.display=this.checked?'':'none'"> Terms1<br>
    <li><input type="checkbox" onclick="document.getElementById('info_terms2').style.display=this.checked?'':'none'"> Terms2<br>
    
    <br>
    <div id="info_terms1" style="display:none;"> terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    terms1 condition <P>
    
    </div>
    
    <div id="info_terms2" style="display:none;"> 
    terms2 condition <P>
    terms2 condition <P>
    terms2 condition <P>
    terms2 condition <P>
    </div>
    If you want to check by default, then add a checked attribute:
    Code:
    <input type="checkbox" onclick="document.getElementById('info_terms1').style.display=this.checked?'':'none'" checked="checked">
    ...and remove the show the corresponding div, by removing highlighted:
    Code:
    <div id="info_terms1" style="display:none;">
    Hope that makes sense.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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