Solved

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

Posted on 2013-02-04
6
305 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
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.

 

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

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now