views:

55

answers:

1

Hello,

Lets say there is a form with a submit button. I found out that using javascript i can call the click() method for input elements in Firefox which would simulate the mouse click on that element.

But then, i got this question, can you detect if button was clicked with real computer mouse, or .click() method?

Thank you

+3  A: 

You can trigger a test using onmousedown from the element in question.

Keep in mind the following though:

  • If your type="submit", you can use the same function that envokes .click() to just submit the form like ~formName.submit();
  • If type="button" and for some reason you have an onclick event handler that submits the form, your onclick events will be invoked whether you call .click() or actually click the button.
  • onmousedown events will not be called using .click().
Babiker