Обработка списка 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>
но при этом список пропадает со страницы. как его зафиксировать? |
нашел решение.
<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>
|
Все куда проще:
function _go(url) {
location.href = url;
}
<select onchange='_go(value)'> Кстати, выбор пункта Все страны исключен? |
| Часовой пояс GMT +3, время: 15:10. |