2

I want to prevent input focus onclick and focus inputs on double click.

Something like....

$('input').click(function) {
    $(this)preventFocus();
});

$('input').dblclick(function) {
    $(this)focus();
});

Or maybe I should use an if statement?

colmtuite
  • 4,311
  • 11
  • 45
  • 67

2 Answers2

5

I guess something like this should work :

$('input').on({
    focus: function() {
        if (!$(this).data('disabled')) this.blur()
    },
    dblclick: function() {
        $(this).data('disabled', true);
        this.focus()
    },
    blur: function() {
        $(this).data('disabled', false);
    }
});

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
1

You could try something like the following

HTML:

<input type="text" id="myInput" readonly="readonly" />

jQuery:

$("#myInput").dblclick(function(){
   $(this).prop("readonly", false)
});
$("#myInput").blur(function(){
   $(this).prop("readonly", true); 
});

See http://jsfiddle.net/KWuR5/