0

I want to execute a Javascript when user set a focus on the submit button.

<input type="submit" id="submit" value="Submit" onfocus="onFocusSubmit()">

But on Safari browser, the event never gets called. I have tried onMouseOver event, which works perfectly well, and I have tried other browsers like Chrome, which also does not have a problem.

Does anybody know a way around this problem?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ham Dong Kyun
  • 756
  • 4
  • 28

1 Answers1

0

I had a workaround as following. I set a keydown event on the previous object (which is not a button)

document.querySelector('#password').addEventListener('keydown', function(e) {
    if (e.key != "Tab" && e.key != "Enter") return;
    //Execute();
});

Also I put a same function when it gets mousemove on the button.

document.querySelector('#submit').addEventListener('mousemove', function(e) {
    document.querySelector('#submit').focus();
    //Execute();
});
Ham Dong Kyun
  • 756
  • 4
  • 28