Forum Moderators: open
I have designed a leaving form with 18 check boxes. Once a user has selected one, the others are then disabled. This works fine (code below). But my problem is that if a user changes his mind and de-selects the check box, then how can I re-enable all the check boxes. Currently the code disables that one as well.
Here is the calling HTML and Javascript code.
Hoping someone can help
Cheers
Gregg
<TD><INPUT id=reason_2 type=checkbox name=tmReason onclick="&chr(34)&"javascript:Reason('Redundancy');"&chr(34)&"></TD>
Javascript:
function Reason(ReasonName)
{
var tempObj;
var tempOBJ2;
for (i=1; i<=18; i++)
{
tempOBJ=eval("document.EC_11655.reason_" +i);
tempOBJ2 = ReasonName
if (tempOBJ.checked)
{
tempOBJ.value=tempOBJ2
tempOBJ.disabled=false;
alert(tempOBJ.value)
}
else
{
tempOBJ.disabled=true;
tempOBJ.value='FALSE'
}
}
}
I've also tried changing the form to use radio buttons but have ended up with a situation where the user can not only select multiple radio buttons but then can't turn them off I.e delesect them!
So I guess it's back to check boxes.
Any ideas?
Thanks
Gregg
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function clearRads(radsNam){
var rads=document.getElementsByName(radsNam);
var rads_ln=rads.length;
for(var i=0;i<rads_ln;i++){
rads[i].checked=false;
}
}
</script>
</head>
<body>
<form action="">
<input type="radio" name="radOne" /><br />
<input type="radio" name="radOne" /><br />
<input type="radio" name="radOne" /><br />
<a href="#" onclick="clearRads('radOne')">Clear Radio Buttons</a>
</form>
</body>
</html>
And here's an alternative using checkboxes:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function ckSet(ck){
var ck_arr=document.getElementsByName(ck.name);
var ca_ln=ck_arr.length;
if(ck.checked){
for(var i=0;i<ca_ln;i++){
if(ck_arr[i].id!=ck.id)ck_arr[i].disabled=true;
}
}else{
for(var i=0;i<ca_ln;i++){
ck_arr[i].disabled=false;
}
}
}
</script>
</head>
<body>
<form action="">
<input type="checkbox" id="ck1" name="ckOne" onclick="ckSet(this)" /><br />
<input type="checkbox" id="ck2" name="ckOne" onclick="ckSet(this)" /><br />
<input type="checkbox" id="ck3" name="ckOne" onclick="ckSet(this)" /><br />
</form>
</body>
</html>