[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
How_To_Javascript_Disable_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

last edited (April 19, 2004) by leeos, Number of views: 1765, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. 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 Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.