[thelist] Toggle disable/enable of text box

Jonathan Chard jonathan at familygenetix.com
Thu Jan 18 10:39:31 CST 2001


Joshua said:
>> Try this:

>> <form>
>> <input type=checkbox onclick="test.disabled =this.checked; return true;">
>>  <input name="test" value="Enter text here">
>>  </form>

Which is right, it will work, but it doesn't explain why your way didn't. I
think the problem you had with your particular way
(if (this.checked) {test.disabled = 'true'} else {test.disabled='false'} )

was that you were returning the string values 'true' and 'false' rather than
the literal Booleans true and false (without the quotes)

so: 'false' == something == not false

If you see what I mean..!

Err... did that help?! Hopefully this info will be useful in finding your
next bug, whenever that may turn up.

(It's still good practice to return values from your event handlers,
though.)

Cheers,
Jon Chard.

-----Original Message-----
To: 'thelist at lists.evolt.org'
Subject: [thelist] Toggle disable/enable of text box


I have a form where I want to disable an input box if a checkbox is checked
(see code below).  Now, it works fine when I check the box.  But when I
uncheck the box it does not become enabled again.  I only need this to work
in IE5+ browsers.  Is this a bug?

<form>
<input type=checkbox onclick="if (this.checked) {test.disabled = 'true'}
else {test.disabled='false'}">
<input name="test" value="Enter text here">
</form>

---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list