Entry
If checkbox is ticked, how do I disable multiple text boxes?
Apr 15th, 2003 08:58
Gauthier Delamarre, Steve Woolston,
To disable any form element by checking a checkbox input, the best way
is certainly to use a user defined function like this :
<script>
function disableEntries(formObj)
{
// Test if the checkbox were checked
if(formObj.myCheckbox.checked)
{
// The box was checked, let's disable some text elements
formObj.firstTextEntry.disabled = true
formObj.secondTextEntry.disabled = true
}
else
{
// The box was unChecked
formObj.firstTextEntry.disabled = false
formObj.firstTextEntry.disabled = false
}
}
<!-- Now, we have to create the form itself -->
<form name=myForm action=whatIwant.php>
First field : <input type=text name=firstTextEntry><br>
First field : <input type=text name=secondTextEntry><br><br>
<input type=checkbox name=myCheckBox
onClick="disableEntries(this.form)"> Disable /
Enable these two fields
</form>
This code should do the trick (untested, but ... used many times in
other context).
Hope this help