1

I want to create a menu for right click on a text box and upon clicking on that option I should be able to call a js function. How should I do it? Can anybody please help me? My code for the text box is:

<g:textField size="40" name="txtBoxId" id="txtBoxId" title="" value="${session.circuitName}" readonly="true"/>
shA.t
  • 16,580
  • 5
  • 54
  • 111

2 Answers2

0

try this.

SEE DEMO

html:

<input id="textbox"/>

js:

 $("#textbox").on('contextmenu', function (e) {
        alert("right-click!");
        window.event.returnValue = false;
 });
Dyrandz Famador
  • 4,499
  • 5
  • 25
  • 40
0

You can do something like this.

HTML:

<input id="id" type="text" />

JavaScript:

var inputBox = document.getElementById("id");
inputBox.addEventListener("contextmenu", handler, useCapture); // useCapture: true or false

//inputBox.attachEvent("oncontextmenu", handler); // IE <9; use attachEvent for IE <9 support.


function handler(event) {
    // your code goes here
    alert("right click on inputbox")
    event.preventDefault();
    event.returnvalue = false; // IE <=9;
}

Here is my example: DEMO

Abdul Alim
  • 346
  • 3
  • 15