4

I need a way of capturing onclick, for a text input that is disabled. I would prefer not to use jQuery, but if there was no javascript alternative, would use it. Thanks in advance

EDIT: I have tried simply adding an onclick="" to a disabled text field, which did not work. Is there any way to do it without jquery? Thanks

user2370460
  • 7,470
  • 10
  • 31
  • 46

3 Answers3

6

How about delegation events to parent elements like here?

<span style="position:relative;" onClick="event.target.value='clicked';">
  <input type="text" disabled "/>
</span>

If my answer is acceptable please comment it and I'll make an explanation.

Serg
  • 1,347
  • 1
  • 8
  • 15
0

You are probably lookinf for this:-

$("div").click(function (evt) {
    $(this).hide().prev("input[disabled]").prop("disabled", false).focus();
});

DEMO JSFIDDLE

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
-1

This is the modified jsfiddle proposed by Rahul Tripathi using pure javascript.

This is the function that made it works:

document.getElementById("textInput").onclick = function() {
    alert("Input clicked");
}
service-paradis
  • 3,333
  • 4
  • 34
  • 43