views:

1128

answers:

2

Ok..this should be pretty straightforward:

<input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;" onmouseout="this.disabled=false;">

if i mouseover this button, it gets disabled..yay! But now when I mouseout, it doesn't get enabled...boo.

I understand the concept of disabling it means you can't do anything with it. But, how do you get it to be enabled with a mouseout? Is it possible? Am I having a brainfart and am missing something? this should be quite easy.

Thanks!

+4  A: 

You should set the mouseout to disabled = '' instead.

<input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;" onmouseout="this.disabled='';">

The disabled property only looks to see if it's there at all. You can set disabled='anything' and it will be disabled. It used to be that you only needed the keyword disabled in your attributes but for valid XHTML you need to set every attribute equal to something.

EDIT: I played around with this a little bit and added some padding to the SPAN tag and it allows the events to work properly. Without padding, it's not trapping the events because the input button is disabled. I just made the background red so it was easy to see the area the SPAN used up.

<span style="padding: 8px; background: red;"  onmouseout="this.firstChild.disabled='';"><input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;"></span>
Shawn Steward
@Shawn: Thanks for that, but unfortunately, that doesn't work either :(
Loony2nz
As others have said, the events won't fire once it is disabled. You can wrap it in a span tag, but that acts a little funky because of the way events bubble up. Are you using any javascript frameworks like MooTools or jQuery?
Shawn Steward
@Shawn: Unfortunately, no. yeah it would have been nicer, cleaner, and unobtrusive had I had a framework, which is why I posted this, the old fashioned way (a.k.a. old skool). I'll give your code a try.Thanks for your input!
Loony2nz
That worked for me in IE8, FF2 and Chrome. It may work better if you use a CSS styled link button instead of an input button if you can do that.
Shawn Steward
A: 

you could have an outer element that surrounds it and have an onmouseover for that outer element that enables the inner element.

Brian Schroth
@Brian: your concept works...in IE, but not FF. This is my code:`<span onmouseout="document.getElementById('test').disabled='';">``<input type="button" name="test" id="test" value="roll over me"` `onmouseover="this.disabled=true;" onmouseout="this.disabled='';">``</span>`
Loony2nz
oh and i removed the onmouseout attribute from the button.
Loony2nz
'<span onmouseout="document.getElementById('test').disabled='';">' '<input type="button" name="test" id="test" value="roll over me"' 'onmouseover="this.disabled=true;">''</span>'Still only works in IE.
Loony2nz