samturner
samturner

Reputation: 2223

Enable input selection but disable text entry

I'm wondering if there is a way to allow a form to be selected (clicked) but at the same time make the form unable to have text entered.

I've tried using readonly which gave me the functionality but the cursor it provides is the same as if I set disabled=true and it greys out the input field which is confusing for the user. Is there any alternatives?

Upvotes: 0

Views: 611

Answers (1)

Popnoodles
Popnoodles

Reputation: 28409

<input class="notype" />

$('.notype').on('keydown', function(e){
    e.preventDefault();
})

What you haven't told us is why. If it's because you want it to be copied to clipboard but not changed, the above won't let you do that, if so please elaborate.

Upvotes: 4

Related Questions