...

View Full Version : checkbox trouble



many_tentacles
05-08-2006, 10:59 AM
Hi

I'm having trouble getting a set of checkboxes to hide/show some hidden info...

if there is more than 1 checkbox ticked, nothing will turn off again??!!!!

Any ideas what i need to do to cure this problem

Here's the source code (http://www.standardcraze.co.uk/test.htm)

Thanks

Kor
05-08-2006, 11:23 AM
you gave some of your checkboxes the same name. Do you really need those names to be like that? You might get trouble when sending to the server. Can't u use something like this?

<input type="checkbox" name="group1_1" onclick="rev(0)">a) group1<br>
<input type="checkbox" name="group1_2" onclick="rev(0)">b) group1<br>
<input type="checkbox" name="group1_3" onclick="rev(0)">c) group1<br><br>

<input type="checkbox" name="group2_1" onclick="rev(1)">a) group2<br>
<input type="checkbox" name="group2_2" onclick="rev(1)">b) group2<br>
<input type="checkbox" name="group2_3" onclick="rev(1)">c) group2<br><br>

<input type="checkbox" name="group3_1" onclick="rev(2)">a) group3<br>
<input type="checkbox" name="group3_2" onclick="rev(2)">b) group3<br>

<input type="checkbox" checked name="group3_3" onclick="rev(2)">c) group3<br><br>

If so I might rebuild your code

many_tentacles
05-08-2006, 11:44 AM
sorry, yes, i had changed the names once... i must have reverted back to an old version though.

I've updated the file now... if you could help me with my code, that would be great.

thanks

Kor
05-08-2006, 12:16 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">

function rev(){
var c = document.getElementsByTagName('input');
var j=1;
while(document.getElementById('group'+j+'_d')){
document.getElementById('group'+j+'_d').style.visibility='hidden';
j++
}
for(var i=0;i<c.length;i++){
c[i].checked?document.getElementById('group'+c[i].name.match(/\d{1}/)+'_d').style.visibility='visible':null
}
}
onload=rev;
</script>

</head>
<body>
<div id="group1_d" style="visibility:hidden">Revealed from group 1</div>
<div id="group2_d" style="visibility:hidden">Revealed from group 2</div>
<div id="group3_d" style="visibility:hidden">Revealed from group 3</div>
<input type="checkbox" name="group1_1" onclick="rev()">a) group1<br>
<input type="checkbox" name="group1_2" onclick="rev()">b) group1<br>
<input type="checkbox" name="group1_3" onclick="rev()">c) group1<br><br>

<input type="checkbox" name="group2_1" onclick="rev()">a) group2<br>
<input type="checkbox" name="group2_2" onclick="rev()">b) group2<br>
<input type="checkbox" name="group2_3" onclick="rev()">c) group2<br><br>

<input type="checkbox" name="group3_1" onclick="rev()">a) group3<br>
<input type="checkbox" name="group3_2" onclick="rev()">b) group3<br>
<input type="checkbox" name="group3_3" checked onclick="rev()">c) group3<br><br>

</body>
</html>

many_tentacles
05-08-2006, 12:31 PM
thats perfect.... thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum