[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
How_To_Javascript_Disable_Enable_Multiple_Form_Elements
The function checks if the checkbox control is checked or not. If it is, it iterates through all the controls of the form and disables the ones of type text ie. all textboxes.
Related threads:
disabling form elements
JavaScript FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
How_To_Javascript_Disable_Enable_Multiple_Form_Elements
How to disable or enable multipe form elements?
The example shows how to change the status of several form elements from another form element.<html>
<head>
<script language="javascript">
function DisableText()
{
var count = document.forms[0].elements.length;
for (i=0; i<count; i++)
{
var element = document.forms[0].elements[i];
if (document.form1.check1.checked == true)
{
if (element.type == "text")
{ element.disabled=true; }
}
else
{ element.disabled=false; }
}
}
</script>
</head>
<body>
<form name="form1">
<input type="checkbox" name="check1" onClick="DisableText()"/>
<input type="text" name="text1" id="text1" value="Type some text">
<input type="text" name="text1" id="text2" value="Type some text">
<input type="text" name="text1" id="text3" value="Type some text">
</form>
</body>
</html>The function checks if the checkbox control is checked or not. If it is, it iterates through all the controls of the form and disables the ones of type text ie. all textboxes.
Related threads:
disabling form elements
JavaScript FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
