I need to create a form element
<input disabled type=”text” value=”Shui Mu Tsinghua” />
which is disabled by default. It enables when onmouseover occures.
onmouseover=”this.disabled=false;”
And is disabled by onmouseout
onmouseout=”this.disabled=true;”
What I need is to check the following.
If the <input> is focused then it shouldn’t be disabled.
And if the form element loses focus it disables.
Please help me to complete the events.
<input disabled type=”text” value=”Shui Mu Tsinghua” onmouseover=”this.disabled=false;” onfocus=”???” onblur=”???” onmouseout=”if(???){this.disabled=true;}” />
This won’t work, as
onmouseoverdoes not fire on disabled inputs, in most browsers. (Opera is an exception, and IE usually doesn’t, except when you trick it with a drag operation.)In any case it sounds like a pretty weird and user-unfriendly trick to me. Why do you want it disabled? If it becomes non-disabled when you try to interact with it there doesn’t seem to be any point to it (but plenty of accessibility downside).
If it’s just a styling thing, then use styles:
However, IE<8 doesn’t support
:focus, and IE<7 doesn’t support:hoveron non-links, so if you need it to work on that you would have to add some scripting, eg. something like: