What i need is Toggle the each div with the relevant check box

ex:- when i checked "div1chk" i want to toggle "div1"

<input type="checkbox" id="div1chk" />
<input type="checkbox" id="div2chk" />
<input type="checkbox" id="div3chk" />


<div id="div1">
div1 showed
</div>
<div id="div2">
 div2  showed
</div>
<div id="div3">
div3  showed
</div>

This should do the trick:

<script type="text/javascript">
function toggleVis(id) {
var vis1 = document.getElementById(id).style.display;
if (vis1 == "inline") {
document.getElementById(id).style.display = "none";
} else {
document.getElementById(id).style.display = "inline";
}
}
</script>

<input type="checkbox" id="div1chk" onclick="toggleVis('div1');" />
<input type="checkbox" id="div2chk" onclick="toggleVis('div2');" />
<input type="checkbox" id="div3chk" onclick="toggleVis('div3');" />

<div id="div1" style="display:none;">
div1 showed
</div>
<div id="div2" style="display:none;">
 div2  showed
</div>
<div id="div3" style="display:none;">
div3  showed
</div>

~G

This should do the trick:

<script type="text/javascript">
function toggleVis(id) {
var vis1 = document.getElementById(id).style.display;
if (vis1 == "inline") {
document.getElementById(id).style.display = "none";
} else {
document.getElementById(id).style.display = "inline";
}
}
</script>

<input type="checkbox" id="div1chk" onclick="toggleVis('div1');" />
<input type="checkbox" id="div2chk" onclick="toggleVis('div2');" />
<input type="checkbox" id="div3chk" onclick="toggleVis('div3');" />

<div id="div1" style="display:none;">
div1 showed
</div>
<div id="div2" style="display:none;">
 div2  showed
</div>
<div id="div3" style="display:none;">
div3  showed
</div>

~G

thank you this is working can you help me to create a effect like

slideToggle("slow");

so here are lots of solution for you and us. thanks for this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.