prakashkadakol
prakashkadakol

Reputation: 1237

Disable right click on form field level

I am need of generic function which can disable right click on the form fields.

Upvotes: 0

Views: 3679

Answers (4)

Fran Verona
Fran Verona

Reputation: 5476

If you need an special context-menu to your form fields, you can use this JQuery plugin:

http://www.javascripttoolbox.com/lib/contextmenu/index.php

Used like this:

var menu1 = [
      {
        'Option 1': function(menuItem,menu) { alert("You clicked Option 1!"); } 
      },
      {
        'Option 2': function(menuItem,menu) { alert("You clicked Option 2!"); } 
      }
];
$(function() {
  $('#myform:input').contextMenu(menu1,{theme:'vista'});
});

So, when the user click on any input fields of your form with id 'myform', the personal context menu will be displayed.

Upvotes: 0

Nabab
Nabab

Reputation: 2644

document.oncontextmenu = function(e) {
  var el = window.event.srcElement || e.target;
  var tp = el.tagName || '';
  if ( tp.toLowerCase() == 'input' || tp.toLowerCase() == 'select' || tp.toLowerCase() == 'textarea' ){
    return false;
  }
};

Upvotes: 3

The_Butcher
The_Butcher

Reputation: 2488

Probably a bad idea (annoys users because it goes against user accepted standard behavior) but you can do it in jQuery like this:

$(function() {
     $(this).bind("contextmenu", function(e) {
         e.preventDefault();
     });
}); 

Upvotes: 1

Piskvor left the building
Piskvor left the building

Reputation: 92752

Can't be done - not reliably and cross-browser (FF, IE, Chrome, Opera) anyway.

There are browser-specific hacks which work in IE and FF, but there's a deeper problem: what are you trying to achieve? Limiting the user experience like this gains you nothing (they already have your precious code, else they wouldn't see the page), and annoys the users.

Upvotes: 1

Related Questions