grabury
grabury

Reputation: 5559

How to right click to select text in textarea

Is it possible to right click on a textarea to select the text and bring up the options dialogue at the same time?

I want to eliminate the additional click of left clicking to select all the text and then right clicking to select 'copy' in

<textarea onclick="this.focus();this.select()" readonly="readonly">
example text
</textarea>

Upvotes: 1

Views: 3548

Answers (4)

user2851392
user2851392

Reputation:

Use the oncontextmenu event as in this example:

<div oncontextmenu="this.focus();this.select();return false;" readonly="readonly">
    example text
</div>

Use "return false" if you don't want the standard context menu to pop up, just in case you changed your mind.

Upvotes: 0

shenhengbin
shenhengbin

Reputation: 4294

Just a different way to implement the RIGHT CLICK by Jquery.

event.which == 3 means right click.

$('textarea').mousedown(function(event) {
if(event.which == 3){
    var THIS = $(this);
    THIS.focus();
    THIS.select();
  }
});

Upvotes: 0

PSK
PSK

Reputation: 152

oncontextmenu is the event you are looking for.

<textarea oncontextmenu="this.focus();this.select()" readonly="readonly">
example text
</textarea>

for reference http://jsfiddle.net/EyNWz/

hope it helps.

Upvotes: 1

Psych Half
Psych Half

Reputation: 1411

just use oncontextmenu instead of onclick..

Upvotes: 4

Related Questions