I've found a different solution to get me where I need to be, but this problem is still plaguing me. I have a checkbox that I want to flip between disabled and enabled, but I can't do it in the code behind, and there will be no post back between the time that I need the state to change.
The thing is, I've been all over the net and I've seen dozens of posts of people w/this same problem who all seem to get it to work. I've used their code and still can't get it to work.
So here's what I have for very very basic code:
I can get the HideCb to disable the checkbox, but I cannot get the ShowCb to enable it! The alert confirms that the code is executing in the correct path, but it just doesn't seem to affect it at all.
function flipCB(cbID, state)
var cb = document.getElementById(cbID);
if(cb != null)
cb.disabled = state;
alert(cb.disabled + "; should be = " + state);
<input type="checkbox" id="cb1" /><br /><br />
<input type="button" value="HideCb" onClick="flipCB('cb1', 'true');" />
<input type="button" value="ShowCb" onClick="flipCB('cb1', 'false');" />
I've tried this is FF3 and IE7.
If someone can point out why I'm a moron, it would help me sleep tonight lol .
EDIT: and yes, I used the search feature here, but did not find anyone who hadn't solved the problem with code that worked for me.
Last edited by Phrozt; 06-30-2009 at 03:50 PM.
Try removing the tick marks [ ' ] from around the true and false in your flipCB call
Also, when you check if document.getElementById(cbID) is valid you can just do....
Wow!! That was it!! Haha... I knew it would be something ridiculously simple. And thanks for the tip about checking for nulls. Clearly js is not my forte .
So why in the world would it recognize 'true' as valid, but not 'false'???
Ah well.. don't want to get my head started on that.
Thanks again for the answer!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)