Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript enable input on double click

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/

like image 561
Umbrella Avatar asked Jul 03 '12 23:07

Umbrella


People also ask

How do I double click in JavaScript?

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.

How do you execute a JavaScript function when a button is double clicked?

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).

What does Ondblclick do in JavaScript?

The ondblclick attribute fires on a mouse double-click on the element.

How do you handle double click?

To handle a double click event using jQuery, use the dblclick() event. When an element is double clicked, this event occurs.


2 Answers

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/

like image 150
JonWarnerNet Avatar answered Oct 22 '22 03:10

JonWarnerNet


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>
like image 35
Gabe Avatar answered Oct 22 '22 03:10

Gabe