[thelist] Toggle disable/enable of text box

Joshua OIson joshua at alphashop.net
Thu Jan 18 11:09:31 CST 2001


In JavaScript, *all* data types are strings.  So, an unquoted true, because
it is a keyword, is the same is a quoted true, so (true=='true') is true.

Event the way I coded it, it still fails if you do not put the return true
at the end of the event.  So, it's more than good practice, it's the way it
has to be coded to make it work.  When events I code don't work as expected,
adding a return value of true is the first thing I do, and in 90% of the
cases it fixes the problem.  It saves me from have to look the event handler
up in a book to check to see if it needs one.

-joshua

----- Original Message -----
From: "Jonathan Chard" <jonathan at familygenetix.com>
To: <thelist at lists.evolt.org>
Sent: Thursday, January 18, 2001 7:11 AM
Subject: RE: [thelist] Toggle disable/enable of text box


> 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.






More information about the thelist mailing list