Solved

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

Posted on 2010-09-09
4
587 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
ID: 33638569
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
ID: 33638914
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
ID: 33639035
Thanks
0
 
LVL 1

Author Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 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