How do i detect right click event for onClick()?

i have javascript code as follow..

<script language=javascript>
function assignGroup(){
     alert(event.button);
}
</script>

<FONT SIZE=1.8 FACE =ARIAL COLOR=#006043 onClick=displayMenu()>My Text</FONT>

my question is,when user click on My Text, how do i know either the user is using right click or left click?

from the code above.. i get 0 for event.button when i left click at the text button get nothing when i right click on the text..please guide...

thanks
pleasureAsked:
Who is Participating?
 
eyal_mtConnect With a Mentor Commented:
use:

<FONT SIZE=1.8 FACE =ARIAL COLOR=#006043 oncontextmenu=displayMenu()>My Text</FONT>

instead of onclick
your displayMenu function will only be called when the user right click on your tag.

to prevent the original popup menu from IE use:
event.returnValue=false;

inside your displayMenu function
0
 
CJ_SCommented:
try onMouseUp instead of onClick.

CJ
0
 
eyal_mtCommented:
IE has the oncontextmenu event which only occurs for right clicks so you can use it with a different funtion.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
pleasureAuthor Commented:
CJ:
onMouseUp didn't give any response...:(

eyal_mt:
can you please explain more about your method.. i'm quite new in JavaScript..:p


thanks...
0
 
b1xml2Commented:
<html>
<head>
<title>Click</title>
<script language="javascript">
function checkClick() {
 alert("Event Button - " + event.button + "\n" + (event.button == 1 ? "Main" : "Secondary") + " Button Clicked");
}
</script>
</head>
<body>
<font size="1.8" face="arial" color="#006043" onmouseup="checkClick()">my text</font>
<ol>
<li><b>Main Button Usually Refers To The Left Click And Returns A Value Of 1</b></li>
<li><b>Other Buttons Return Values Other Than 1</b></li>
</ol>
</body>
</html>
0
 
b1xml2Commented:
Works for MSIE4+
0
 
b1xml2Commented:
as per CJ_S suggestion =). So, CJ_S should get credit for this.
0
 
pleasureAuthor Commented:
yupe.. oncontextmenu() works...:) thanks...

menuPopup = window.createPopup();
menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body);

i used code above to popup my menu, is there any way for me to set my background color of my popup menu? Currently it's showing with color.

0
 
pleasureAuthor Commented:
actually..both of the solution work..but since i'm using eyal_mt solution so i think it's better for me to reward him/her..thanks a lot to all of you...:)
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.