Solved

div Show-Hide-Div-Layer-Deselect-Checkboxes

Posted on 2013-02-04
6
295 Views
Last Modified: 2013-02-14
hello, i want to create a page with event and seminars, when i deselect seminar, i only want to view all events, but, with these code it doensn't work, only the first div (1) desepears, not all div(1) 's...

can someone help me? thx

<script>
function showMe (it, box) {
  var vis = (box.checked) ? "visible" : "hidden";
  document.getElementById(it).style.visibility = vis;
}
</script>
<div id="div1">
<h3 align="center">this is event 1 </h3>
<table border=1 id="t1">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>

<div id="div2">
<h3 align="center">this is seminar 1</h3>
<table border=1 id="t1">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>


<div id="div1">
<h3 align="center">this is event 2 </h3>
<table border=1 id="t1">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>


<form>
<input type="checkbox" name="c1" onclick="showMe('div1', this)" checked>Event
<input type="checkbox" name="c1" onclick="showMe('div2', this)" checked>Seminaire


</form>

Open in new window

0
Comment
Question by:fedkris
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38850385
Try below code.

function showMe (it, box) {
  var vis = (box.checked) ? "display" : "none";
  document.getElementById(it).style.display = vis;
}
0
 

Author Comment

by:fedkris
ID: 38850391
it doensn't work, no good results
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 38850714
I think what @EaswaranP meant was:

Try below code.

function showMe (it, box) {
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it).style.display = vis;
}
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:fedkris
ID: 38850812
hey, thx for reply, only the first event disepears, not the two events...
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 38850887
First, you need to have a way to identify which divs are seminar and which are event. Also, when assigning ids to elements, all ids must be unique on the page.

If you don't mind using jquery you can do something like this:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("input[name='c1']").bind('click', function(){		
		if($(this).attr('checked')){
			$('div.' + $(this).attr('data-type')).show();
		}else{
			$('div.' + $(this).attr('data-type')).hide();
		}
	});
});
</script>
</head>

<body>
<div class="event" id="div1">
<h3 align="center">this is event 1 </h3>
<table border=1 id="t1">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>

<div class="seminar" id="div2">
<h3 align="center">this is seminar 1</h3>
<table border=1 id="t2">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>


<div class="event" id="div3">
<h3 align="center">this is event 2 </h3>
<table border=1 id="t3">
<tr>
<td>i am here!</td>
</tr>
</table>
</div>


<form>
<input type="checkbox" name="c1" data-type="event" checked>Event
<input type="checkbox" name="c1" data-type="seminar" checked>Seminaire


</form>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:fedkris
ID: 38888496
i will look for something else
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now