Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Обработка списка select (https://javascript.ru/forum/events/54069-obrabotka-spiska-select.html)

Schokk 02.03.2015 16:59

Обработка списка select
 
Здравствуйте. Задача такова. Нужно что бы при выборе значения из списка открывалась соответствующая страница. Я реализую это так.
<script type="text/javascript">
var adres1=window.location.pathname.toString();
var res=adres1.indexOf('full') + 1;
if(!res){
document.write("<select name='countries' id='countries' onchange='with (this) if (selectedIndex) location = options [selectedIndex].value'>");
document.write("<option value='0'>Все страны </option>");
document.write("{start}<option {selected} value='/activity/{categ}/1/{id}-{translit}/{sortBy}'>{name} ({count})</option>{end}</select>");
}
</script>

но при этом список пропадает со страницы. как его зафиксировать?

Schokk 02.03.2015 17:28

нашел решение.
<script type="text/javascript">
function _go() {
    //alert(document.getElementById('address').options[document.getElementById('address').selectedIndex].value);
    location.href=document.getElementById('adress').options[document.getElementById('adress').selectedIndex].value;
}
var adres1=window.location.pathname.toString();
var res=adres1.indexOf('full') + 1;
if(!res){
document.write("<select name='countries' onchange='_go()' id='adress' class='countries'>");
document.write("<option value='0'>Все страны </option>");
document.write("{start}<option {selected} value='/activity/{categ}/1/{id}-{translit}/{sortBy}'>{name} ({count})</option>{end}</select>");
}
</script>

danik.js 02.03.2015 18:09

Все куда проще:
function _go(url) {
    location.href = url;
}


<select onchange='_go(value)'>


Кстати, выбор пункта Все страны исключен?


Часовой пояс GMT +3, время: 05:28.