How can I detect which button clicked with onclick event handler.

gen228
gen228 used Ask the Experts™
on
Hi, if I am using the onclick event handler, how can I detect a right or left mouse click.  I cannot use the onMousedown handler.

-Thanks noijet
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hi,

The onClick event Fires when the user presses and releases the left mouse button, or when the user presses keys, such as ENTER and ESC, in a form.

<script language=JavaScript>
function getClick(e)
  {
  if (document.all)
    { alert(event.button); }
  else if (document.layers)
    { alert(e.which); }
  else if (document.captureEvents)
    { alert(document.captureEvents(Event.MOUSEDOWN)); }
  }

document.onmousedown=getClick;
</script>
Michel PlungjanIT Expert
Top Expert 2009

Commented:
gen228,
No comment has been added lately (309 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to kanithi http:#7455082

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

mplungjan
EE Cleanup Volunteer

Author

Commented:
Thanks for the advice !  I apologize for the delay and thanks for the assist mplungjan !

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial