Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link in a <select> with JS doesn't work on Chrome. IE & FF it works

one simple question:

Why this code works perfectly in FF and IE and in Chrome it doesn't?

<select  class="langbox" name="forma">
        <option class="text-option" onClick="window.location = 'http://www.myurl/it'" >Italiano</option>
        <option class="text-option" onClick="window.location = 'http://www.myurl/en'" >English</option>
        <option class="text-option" onClick="window.location = 'http://www.myurl/de'" >Deutsch</option>
        <option class="text-option" onClick="window.location = 'http://www.myurl/fr'" >Français</option>
        <option class="text-option" onClick="window.location = 'http://www.myurl/ru'" >Pусский </option>

    </select>

It doesn't redirect me on the url I want, it does nothing on Chrome. In Firefox and IE it works.

like image 416
Andrea Giachetto Avatar asked Dec 09 '25 09:12

Andrea Giachetto


1 Answers

<select class="langbox" name="forma" onChange="window.location
                 ='http://www.myurl/'+this.options[this.selectedIndex].value;">
    <option class="text-option" value="it">Italiano</option>
    <option class="text-option" value="en">English</option>
    <option class="text-option" value="de">Deutsch</option>
    <option class="text-option" value="fr">Fran&ccedil;ais</option>
    <option class="text-option" value="ru">Pусский</option>
</select>

You don't click on options, you change the select. While some browsers may be tolerant of this, others may not be (as you have discovered). Especially mobile browsers, which may have a completely different UI for <select> elements.

like image 180
Niet the Dark Absol Avatar answered Dec 11 '25 23:12

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!