Link to home
Start Free TrialLog in
Avatar of Sailing_12
Sailing_12

asked on

jQuery - Select AND show context menu on textbox right-click

I'm using the script below and the jQuery right-click plugin to modifiy the behavior of all text boxes on a form to select all content upon right-click.

Works OK except that I've lost the default context-menu behavior which I'd like to keep.

Anyone know how to ge this back along with the auto-select?
$(function() {
           $('input[type=text]').rightClick(function(e) {
               this.select();
               //alert("Got it");

           });
       });

Open in new window

Avatar of tdot
tdot

Not sure what you mean >lost works OK except that I've lost the default context-menu behavior which I'd like to keep.
one thing I would like to point out...to get the current obj reference instead of
      this.select();

you should be using:

     $(this).select();
Avatar of Sailing_12

ASKER

When you right-click on a standard textbox, a default context menu appears with items like Cut, Copy, Paste, etc. The script I have implemented above seems to prevent this menu from appearing at all.

Ideally, I would like the right-click event to both select the entire content string of the textbox AND trigger the standard context menu to appear so that a user can simply right-click and Paste to replace the entire string, a phone number in this case.
Since I haven't got much response yet, I'm increasing the points for this question to 500.
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK. So would my page script then look like this since we are calling the select action from the plugin instead of the page head?


$(function() {
           $('input[type=text]').rightClick(function(e) {});
       });

Open in new window

yes...correct
what browser are testing in
OK. Seems to work. Thanks.