Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form Processing in PHP 11 30
Change javascript css 1 17
tag title an image 13 15
geting geocode of a user with using Google maps api 8 14
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

919 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

13 Experts available now in Live!

Get 1:1 Help Now