Rohit Sharma
Rohit Sharma

Reputation: 103

disable enable a textfield dynamically

Hi I was trying to make a textfield dynamic. This is my code

 <input type="text" id="test1" value ="dynamic" onfocus="this.disabled=true" onblur="this.disabled=false">
    <input type="text" id="test2">

so fields get disabled perfectly but doesnt get enabled on blur. If any one here can solve my problem that would be great.

Upvotes: 1

Views: 5331

Answers (2)

Abhishek Das
Abhishek Das

Reputation: 82

Why don't you use onmouseover and onmouseout events on your text field instead ?

<input type="text" id="test1" value="dynamic" onmouseover="this.disabled=true" onmouseout="this.disabled=false">

Upvotes: 0

PeeHaa
PeeHaa

Reputation: 72729

Perhaps in this situation it is better to make the field readonly and add some custom class to make it look like it is disabled.

Since disabled element are well... disabled :)

EDIT

I've done some testing and it gets enabled again on blur!

http://jsfiddle.net/dfhHz/

You still need to click outside the input to trigger the blur ofcourse

EDIT2

WHat would you like to achieve. Since this functionality looks a bit strange (disable on focus and enable on blur) to me :)

Upvotes: 1

Related Questions