Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
why 'onfocus' does not work on multiple select option, and 'onclick' does?

I do not see why onfocus='myFunction()' works in a an input, but not in an option, for example:

<input type="text" id="fname" onfocus="myFunction()">

calls myFunction when you click on it or when you tab into it, but:

<select multiple>
<option onfocus="myFunction()">whatever</option>
</select>

Does not work when you step in the option.

Why is this? I cannot find a documentation which says what events work on what elements. I have seen this for a long time, but now I want to know why

EDIT: I am using Chrome.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please look at the MDM web docs

For onfocus to fire on non-input elements, they must be given the tabindex attribute

So in other terms: give the option with the focus event a tabIndex! The example below should work.

function myFunction() {
      console.log("focus");
}

function myFunction2() {
      console.log("focus2");
}
<select multiple>
    <option tabIndex="0" onfocus="myFunction()">whatever</option>
    <option tabIndex="0" onfocus="myFunction2()">whatever2</option>
</select>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!