...

View Full Version : Enable disabled checkbox via select list



nikko50
09-04-2008, 04:10 AM
Hi all. With the below test form I'm trying to enable the checkbox only when the user select the "CLOSED" option from the select box. Initially when the form loads the checkbox ihas a onClick=\"return false\" event. How can I do this??



<form method="POST" name="theForm" action="--WEBBOT-SELF--">

<p><input type="checkbox" onClick="return false" name="TEST"></p>
<p><select name="STATUS">
<option value="ACTIVE">ACTIVE</option>
<option value="CLOSED">CLOSED</option>
</select></p>

<p><input type="submit" value="Submit" name="B1"></p>
</form>

Philip M
09-04-2008, 07:46 AM
Here you are, Tracy:-


<form method="POST" name="theForm" action="--WEBBOT-SELF--">

<p><input type="checkbox" name="TEST" disabled></p>
<p><select name="STATUS" onchange = "fixTest()">
<option value="ACTIVE">ACTIVE</option>
<option value="CLOSED">CLOSED</option>
</select></p>

<p><input type="submit" value="Submit" name="B1"></p>
</form>

<script type = "text/javascript">
function fixTest() {
x = document.theForm.STATUS.value;
if (x == "CLOSED") {
document.theForm.TEST.disabled = false;
}
else { // if user switches back to ACTIVE
document.theForm.TEST.checked= false;
document.theForm.TEST.disabled = true;
}
}
</script>

Did you receive the PM I sent you a while back?


A single parent would only be able to claim benefits for two years, and after those two years they would be literally pushed over the cliff - Politician

nikko50
09-04-2008, 01:42 PM
Works great and you remembered my name also!

Philip M
09-04-2008, 03:55 PM
Works great and you remembered my name also!

Well, I do tend to remember the names of people who have a great many posts (all requesting assistance) but zero thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum