How to disable or enable form elements?
The example shows how to change the status of a form element from another form element.
<html>
<head>
<script language="javascript">
function Change()
{
if (document.form1.check1.checked == true)
{ document.form1.text1.disabled = true; }
else
{ document.form1.text1.disabled = false; }
}
</script>
</head>
<body>
<form name="form1">
<input type="checkbox" name="check1" onClick="Change()"/>
<input type="text" name="text1" id="text1" value="Type some text">
</form>
</body>
</html>
The function checks if the
checkbox control is checked or not. If it is, the
textbox control will be disabled.
Related threads:
disabling form elements
JavaScript FAQ