I have a form with some inputs disabled. I want these inputs to be enabled when double clicked. Unfortunately, JS events seem not to fire on disabled inputs.
<input type="text" value="asdf" disabled="disabled" ondblclick="this.disabled=false;">
Is there a way around this limitation?
Or am I just going to have to wrap any affected input in a span to house the event?
http://jsfiddle.net/vhktx/
The dblclick event generates an event on double click the element. The event fires when an element is clicked twice in a very short span of time. We can also use the JavaScript's addEventListener() method to fire the double click event. In HTML, we can use the ondblclick attribute to create a double click event.
The dblclick event fires when a pointing device button (such as a mouse's primary button) is double-clicked; that is, when it's rapidly clicked twice on a single element within a very short span of time. dblclick fires after two click events (and by extension, after two pairs of mousedown and mouseup events).
The ondblclick attribute fires on a mouse double-click on the element.
To handle a double click event using jQuery, use the dblclick() event. When an element is double clicked, this event occurs.
ondblclick
does not get fired on a disabled
element, you should mark it as readonly
:
<input type="text" value="asdf" readonly="true" ondblclick="this.readOnly='';">
http://jsfiddle.net/vhktx/4/
You will have to wrap the element in a container since the the event will not fire on disabled elements.
jsFiddle
<div ondblclick="document.getElementById('test').disabled=false;">
<input type="text" id="test" value="asdf" disabled="disabled"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With