ultrahomie,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body><select id="select" name="select">
<option value="1">город1</option>
<option value="2">город2</option>
<option value="3">город3</option>
</select>
<span id="gorod"></span>
<script type="text/javascript" >
var select = document.getElementById('select');
select.onchange = function () {
city();
var date = new Date();
date.setDate(date.getDate() + 7);
document.cookie = 'select=' + select.value +'; path=/; expires=' + date.toUTCString();
}
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
var cookie = getCookie('select');
if (cookie) {
select.value = cookie;
}
function city() {
var target = document.getElementById('gorod'),
cities = {'1':'город1', '2':'город2', '3':'город3'};
target.innerHTML = cities[select.value];
}
city()
</script>
</body>
</html>
|