I am trying to implement a code to hide and show divs with a radio button. If yes is selected i want to show the divs. If no is selected i want to hide them. It sounds simple enouth but i can't figure this out. Can someone please advise.
Here is my code.
<script language="JavaScript" type="text/javascript">
<!--
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none'){
document.getElementById(divid).style.display = 'block';
document.pageLoading.TCallLabel('/','restart_function');
}else{
document.getElementById(divid).style.display = 'none';
}
}
//-->
</script>
<script type="text/javascript">
//***Need the following DIVs hidden until used****
var divs = ["div0", "div1", "div2", "div3", "div4", "div5", "div6"];
function visiblox(arrDiv, hs) {
var disp = (hs) ? "none" : "block";
for(var x = 0; x < arrDiv.length; x++) {
document.getElementById(arrDiv[x]).style.display = disp;
}
}
function prechk(v){
v = v.split(',');
for(var i = 0; i < v.length; ++i){
chk([divs[v[i]]], true);
}
}
function chk(what, item) {
if(item) {
visiblox(what, false);
} else {
visiblox(what, true);
}
}
</script>
<style type="text/css">
<!--
.show
{
display: block;
}
.hide
{
display: none;
}
-->
</style>
</head>
<body>
<div class="rowElem"><label>Vignet:</label>
<input type="radio" id="" name="list" option value="1,2,5,6" onchange="chk(divs); prechk(this.value);"><label>Yes</label>
<input type="radio" id="" name="list" option value="0" onchange="chk(divs); prechk(this.value);" checked><label>No</label></div>
<div id="div0" class="hide"></div>
<div id="div1" class="hide"><div id="buttonvignet"></div><input type="submit" value="Vignet!" /></div>
<div id="div5" class="hide"><img src="http://xxxx/xxxx/images/Vignetjes_10/1.png" id="image-to-change"></div>
<div id="div6" class="hide"><div class="rowElem"><label>Vinet Model:</label><input type="text" value="Vinet Model" readonly="readonly" name="vignet"></div></div>
<div id="div2" class="hide"><div class="rowElem"><label>Label:</label>
<input type="radio" id="" name="search" value="standard" ><label>Yes</label>
<input type="radio" id="" name="search" value="advanced" checked><label>No</label></div></div>
</body>