onclick event in select HTML not working in Safari

19,241

Solution 1

Replacing the onclick event with onfocus solved the problem. I guess Safari doesn't like onclick event on select elements.

Solution 2

Sometimes you need to add preference to the JavaScript function as "javascript:"; for example:

<select onclick="changeDate()">

should be

<select onclick="javascript:changeDate()">

Solution 3

For me in Chrome, onclick working with second click on select box Where as in FF & IE, its working fine for first click itself.

Share:
19,241
Jepe d Hepe
Author by

Jepe d Hepe

Developer / Scrum Master Open-Minded

Updated on June 05, 2022

Comments

  • Jepe d Hepe
    Jepe d Hepe almost 2 years

    I have an ASP.NET dropdown list control with onclick and onchange JavaScript events. Both work in IE, Mozilla, Opera and Chrome, but not in Safari. When I remove the onclick event, onchange suddenly works.

    The reason I use onclick is to get the value of the dropdown list before it changes. Is there a way I can do that without using onclick? That is, get the value of the dropdown list before it changes/a new value is selected? I want to do this in JavaScript only.

    • Jepe d Hepe
      Jepe d Hepe over 14 years
      i've replaced the onclick event to onfocus. problem solved. i guess safari dont like onclick event on select element
    • Ismail
      Ismail about 7 years
      Sorry to bump. For me, I found out that I was using closest which was not supported and that fixes it, after debugging with alert (no console.log on mobile ;))..
  • redolent
    redolent over 7 years
    What helped me was making sure javascript: and () were both there.
  • Liglo App
    Liglo App about 5 years
    @redolent so you weren't sure and it didn't work, than you looked, made sure and it started working? :-D
  • redolent
    redolent about 5 years
    It was that simple, yes
  • jbiser361
    jbiser361 over 2 years
    wow... this helped me 10 years later.... I don't understand why safari has to be build different like this...