Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-02-04
6
Medium Priority
?
346 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
Technology Partners: 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!

 

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 1000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

688 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