The onClick event does not work in Safari, but it works fine in IE / FF / Chrome / Opera

I use onClick JavaScript, it works well with IE / FF / Chrome browser, but does not work with Safari browser.

The code I use is as follows:

heartSelectHandler = { clickCount : 0, action : function(select) { heartSelectHandler.clickCount++; if(heartSelectHandler.clickCount%2 == 0) { selectedValue = select.options[select.selectedIndex].value; heartSelectHandler.check(selectedValue); } }, blur : function() // needed for proper behaviour { if(heartSelectHandler.clickCount%2 != 0) { heartSelectHandler.clickCount--; } }, check : function(value) { alert('Changed! -> ' + value); } } <select onclick="javascript:heartSelectHandler.action(this);" onblur="javascript:heartSelectHandler.blur()" id="heart" data-role="none"> <?php for ($i = 20; $i <= 150; $i++): ?> <option value="<?php echo $i; ?>"><?php echo $i; ?></option> <?php endfor; ?> </select> 
+3
source share
1 answer

Use onchange instead of onclick, as this ensures that changes to the selection purely from the keyboard will also trigger the event as expected (right?).

i.e. Application:

 onchange="javascript:heartSelectHandler.action(this);" 

instead:

 onclick="javascript:heartSelectHandler.action(this);" 
+1
source

All Articles