1

Possible Duplicate:
Event on a disabled input
JQuery register click event while button is disabled

I have a textbox:

<input type='text' disabled='disabled' id='textbox' value='diusabled text' />

In my javascript, I try to bind its click event:

$('#textbox').bind('click', function() { alert ('111'); });

When I click on the textbox, nothing happens, because it's disabled. What can I do in order to make this functionality work?

Community
  • 1
  • 1
benams
  • 4,308
  • 9
  • 32
  • 74
  • 1
    fyi http://api.jquery.com/bind/ "As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document" – robasta Jan 10 '13 at 09:45
  • http://stackoverflow.com/questions/3100319/event-on-a-disabled-input – phnkha Jan 10 '13 at 09:46

3 Answers3

1

You have to create an overlay which handles the click events.

This blog shows you how to do it:

http://blog.pengoworks.com/index.cfm/2010/4/23/Attaching-mouse-events-to-a-disabled-input-element

acuntex
  • 147
  • 13
0

you can not bind event to disabled elements.You have to change from disable to enable firstrst and then assign bind event for that textbox.later on you can disable that textbox again.

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • Of course you can bind events to disabled elements. Just try to bind an event, remove the disabled flag and the events will work. The events just don't fire if the element is disabled. – acuntex Jan 10 '13 at 09:52
0

You can make the textbox readonly to fire event and do not allow edit.

Live Demo

 <input type='text' readonly id='textbox' value='diusabled text' />
Adil
  • 146,340
  • 25
  • 209
  • 204