Love this site? Hate it? Leave us some comments.
*/

Other Views

corner
*/

How to Disable or Enable form Elements

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
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings