How can my input element receive onclick events when it is disabled?

I need to have an onclick / hover event on an input tag that is disabled.
Is there any other way, but wrap it in another tag and give this tag events?

<input type="checkbox" onclick="cant_choose('event')" disabled="disabled" value="2" name="enroll_to[event][]"> 
+6
javascript html input events
source share
2 answers

You can simulate it using JavaScript and CSS.

That is, blur all the focus it gets and add a class with something like this.

 input.disabled { background: #d4d0c8; color: #888; cursor: default; } 

Update

Look at this compared to the input field with a normal and disabled browser on JSbin .

+8
source share

You can wrap the input field inside the container and bind the click event on it.

 <div id='input-container'> <input id='myText' disabled /> </div> <script> $('#input-container').click(function() { alert('test'); }); </script> 

http://jsfiddle.net/M2EYH/

If you have several disabled fields and you do not want to create a unique identifier for each container, you can provide the containers with the class name instead of the identifier.

+1
source share

All Articles