...

View Full Version : Enable/thisable 2 radiobuttons with checkbox



peterr
05-02-2006, 05:33 PM
Hello,


I want to be able to enable 2 radiobuttons of the same group by checking a checkbox and disable them when the box is unchecked.

I've found numerous scripts for enableing and disableing textfields and entire forms but none for radiobuttons of the same group. The script I have now (also from this forum from JohnKrutsch) is:

(simplified for the purpose of posting it here)
-------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>enable/disable radiobuttons</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">

function checkIt(toCheck,toEnable){
a=toEnable.split(",");
for(i=0;i<a.length;i++) document.form2[a[i]].disabled=!document.form2[toCheck].checked;
}

</script>
</head>

<body>

Check the checkbox to enable the radiobuttons.
<br>
<form action="bla.php" method="post" enctype="multipart/form-data" name="form2">
<br>
<strong>Enable the buttons</strong> <input type="checkbox" name="cb" value="checkbox" onClick="checkIt('cb','tx,tf')">
<br><br>

<input type="radio" name="tx" disabled>
<strong>Radio1 </strong><br>
<input type="radio" name="tx" disabled>
<strong>Radio2</strong><br>
Textfield<input type="text" name="tf" disabled>
</form>

</body>
</html>

---------------------------------------------------------------
This works fine except for enableing or disableing the radiobuttons.

Is there any way to get this script to work for buttons of the same group? Or does anyone have another solution?

Thank you for reading this and a big thanks to all the people helping other people out :thumbsup: .

Peter.

vwphillips
05-02-2006, 06:28 PM
http://www.vicsjavascripts.org.uk/FormCompendium/FormCompendium.htm

f7, f40 and others

peterr
05-02-2006, 08:00 PM
Thanks a lot! Didn't try the first but the f40 script works for the radiobuttons.:thumbsup: :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum