?
Solved

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

Posted on 2010-09-09
4
Medium Priority
?
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
bureshd earned 1600 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 400 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 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