onclick event in select HTML not working in Safari
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.
Comments
-
Jepe d Hepe almost 2 years
I have an ASP.NET dropdown list control with
onclick
andonchange
JavaScript events. Both work in IE, Mozilla, Opera and Chrome, but not in Safari. When I remove theonclick
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 usingonclick
? 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 over 14 yearsi've replaced the onclick event to onfocus. problem solved. i guess safari dont like onclick event on select element
-
Ismail about 7 yearsSorry to bump. For me, I found out that I was using
closest
which was not supported and that fixes it, after debugging withalert
(noconsole.log
on mobile ;))..
-
-
redolent over 7 yearsWhat helped me was making sure
javascript:
and()
were both there. -
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 about 5 yearsIt was that simple, yes
-
jbiser361 over 2 yearswow... this helped me 10 years later.... I don't understand why safari has to be build different like this...