1

I need to trigger an ajax-ed element by javascript method:

<h:panelGrid id="g" columns="1" onmouseover="window.document.getElementById(aa).click()">

and it works, except that it doesn't recognize the modifiers.

I looked here http://www.w3schools.com/jsref/met_html_click.asp and modified the try it yourself to look like

<input type="checkbox" id="myCheck" onmouseover="myFunction(event)" onclick="alert('click event occured '+event.ctrlKey)">

but ctrlKey always is false.

Is there a way to persuade the click-method to use and forward the modifiers?

Edit: to clarify the "moused" object and the object that should send the ajax-request are different!

Gyro Gearloose
  • 1,056
  • 1
  • 9
  • 26

1 Answers1

1

When you click with the Control key, it sends the contextmenu event instead of the click event. If you want a general event for all types of mouse clicks, use mousedown.

<input type="checkbox" id="myCheck" onmousedown="alert('click event occurred ' + event.ctrlKey);">

See what's the equivalent of jquery's 'trigger' method without jquery? for a more detailed answer showing how to synthesize mouse click events, including all the different event parameters.

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I'm a bit confused now. I see your example is working, but I don't understand. When I modify the example at w3schools, it doesn't work. – Gyro Gearloose Jan 01 '16 at 15:35
  • And I don't see how I could forward that event to my getElementById(aa) object. – Gyro Gearloose Jan 01 '16 at 15:39
  • See http://stackoverflow.com/questions/5658849/whats-the-equivalent-of-jquerys-trigger-method-without-jquery for how to simulate different types of click events – Barmar Jan 01 '16 at 15:41
  • I see the link ... so I don't have to be ashamed that I couldn't find a two-liner to do it. Could you incorporate the link into your question so that I can accept it? – Gyro Gearloose Jan 01 '16 at 15:46