Solved

hide/ show 2 div tags based on click of a checkbox

Posted on 2010-09-09
4
577 Views
Last Modified: 2012-05-10
Hello Experts,
I have 2 div tags like below
<div id="Div1" style="display:none;">some text</div>
<div id="Div2" style="display:none;"> some more text </div>

now the Div1 and Div2 are located in different parts of my web page, so the idea of wrapping both in one more DIV tag didnt work.

Now i have checkbox which basically says Check here if you want to see "SOME TEXT"

i know i can use this javascript to show and hide one DIV tag but not 2 DIV Tags at the same time
this is the code i have for one div tag

is it possible to show to div tags with a click of checkbox.

thanks and appreciate it




<input type="checkbox"  value="yes" onclick="document.getElementById('Div2').style.display=(this.checked)?'inline':'none';" > check if to see SOME TEXT

Open in new window

0
Comment
Question by:niceoneishere
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
bureshd earned 400 total points
Comment Utility
Don't put the javasript inline with the control. Have it call a javascript function and perform the style change twice, once to each div.  I did this without checking the syntax and running it so you may need to adjust it a little but this should explain the logic. Let me know if this helps. Thanks

<input type="checkbox"  value="yes" onclick="showDivs();" > check if to see SOME TEXT

function showDivs()
{
document.getElementById('Div2').style.display'inline'
document.getElementById('Div1').style.display'inline'
}
0
 
LVL 14

Assisted Solution

by:sam2912
sam2912 earned 100 total points
Comment Utility
Duplicate another?
<input type="checkbox" value="yes" onclick="document.getElementById('Div1').style.display=(this.checked)?'inline':'none'; document.getElementById('Div2').style.display=(this.checked)?'inline':'none';" > check if to see SOME TEXT

Open in new window

0
 
LVL 1

Author Closing Comment

by:niceoneishere
Comment Utility
Thanks
0
 
LVL 1

Author Comment

by:niceoneishere
Comment Utility
Both worked but i went with the function option. Thanks guys and appreciate it
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now