Solved

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

Posted on 2013-02-04
6
333 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
[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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

734 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