Solved

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

Posted on 2010-09-09
4
593 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 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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?
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

724 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