Forum Moderators: open

Message Too Old, No Replies

onRightClick

Does it exist?

         

dougmcc1

3:42 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



I want to have the value of a field disappear on right click, but not on left click.

Is this possible?

Thanks.

whoisgregg

11:44 pm on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A search (at any major SE) for "javascript right click" will bring up a bunch of "Right Click blocker" scripts which should give some insight into how to detect for the right click mouse event. :)

tomruskin

7:41 pm on Dec 15, 2006 (gmt 0)

10+ Year Member



Hi dougmcc1,
Try this out.
function whichButton(event)
{
if (event.button==2)
{
alert("You clicked the right mouse button!")//your code
}
else
{
alert("You clicked the other mouse button!")
}
}

dougmcc1

5:35 pm on Dec 26, 2006 (gmt 0)

10+ Year Member



Great replies, thanks.

How would I pass "event" to the whichButton() function when I don't know the value of it yet (which is the purpose of the function)?

Something like this would work if I already knew which button was clicked:
<input type=text onFocus=whichButton(2)> or <input type=text onFocus=whichButton(event.button)>

But if I cant do that then I need to do something like this:
<input type=text onFocus=determineWhichButtonWasClicked()>

Or this:
<input type=text onRightClick=rightClick() onLeftClick=leftClick()>

netfiends

8:05 am on Jan 5, 2007 (gmt 0)

10+ Year Member



<input type="text" name="whatever" value="" onmousedown="if(event.button==2){alert('right mouse button clicked!');}"> This should do it, just replace alert with what you need done.

netfiends

8:21 am on Jan 5, 2007 (gmt 0)

10+ Year Member



<input type="text" name="whatever" value="" onmousedown="if(event.button==2){whatever.value=''}"> -- should be exactly what you're looking for.