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

sailing_12Asked:
Who is Participating?
 
guru_samiConnect With a Mentor Commented:
See if this is what you are looking for...

open the jquery.rightClick.js and modify rightClick: like this:

      $(this)[0].oncontextmenu = function() {
                    $(this).focus();
                    $(this).select();
                    return true;
                }
P.S. File attached
jquery.rightClick.js
0
 
tdotCommented:
Not sure what you mean >lost works OK except that I've lost the default context-menu behavior which I'd like to keep.
0
 
guru_samiCommented:
one thing I would like to point out...to get the current obj reference instead of
      this.select();

you should be using:

     $(this).select();
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
sailing_12Author Commented:
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.
0
 
sailing_12Author Commented:
Since I haven't got much response yet, I'm increasing the points for this question to 500.
0
 
sailing_12Author Commented:
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

0
 
guru_samiCommented:
yes...correct
0
 
tdotCommented:
what browser are testing in
0
 
sailing_12Author Commented:
OK. Seems to work. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.