Raimund Krämer
Raimund Krämer

Reputation: 1309

Disable HTML input without disabling mouse events

Is it possible to disable an HTML input while keeping mouse events?

I know that disabled="disabled" also stops events from being evaluated. What I need to do is disable clicking on the input element, but still recognize the onmouseover and onmouseout events (for switching background images).

Note that I am not searching for a workaround like making it look disabled with CSS or something like that. I want to actually make it impossible to be clicked (like clicking on an image), but I can NOT just use an image instead.

Upvotes: 3

Views: 2449

Answers (3)

Shamsul Huda
Shamsul Huda

Reputation: 163

You can also solve this problem by using css

<input type="text" name="">

input{

 pointer-events: none;

}

Upvotes: 0

RiccardoC
RiccardoC

Reputation: 866

If I understand, you want that clicking on an input field, you do not want the user to be able to write in it, with the field still not disabled Try this

$(document).ready(function () {
  $( "#input_field" ).on('focus',function(){
    $( this ).blur() 
  });
});

Upvotes: -2

Marcos P&#233;rez Gude
Marcos P&#233;rez Gude

Reputation: 22158

Readonly?

 <input readonly="readonly" type="text">

You can preserve mouse events, but will be impossible to fill with keyboard.

Upvotes: 5

Related Questions