I would like to replace ".city1{background:red;}" with ".city1 with http://city1.example.com" so that when user selects a city1 the page goes to the city1 url page. Since I don't need the color box with a message, can I remove the code:
var cityChosen = getCookie('citychosen');
if(cityChosen!=null && cityChosen!=''){
var chosen = $('#choose option[value="'+cityChosen+'"]');
chosen.attr('selected',true);
$("#output").removeClass().addClass(cityChosen).html("You have selected this last time.<br />" + chosen.text());
}
Any help will be very much appreciated.
<head>
<style type="text/css">
<!--
*{ margin:0; padding:0;}
body{ font:24px Verdana, Geneva, sans-serif; margin:100px;}
#output{ color:#fff; margin:20px 0; padding:50px; height:200px; width:200px;}
.default{ background:#CCC;}
.city1{background:red;}
.city2{background:blue;}
.city3{background:orange;}
.city4{background:plum;}
-->
</style>
<script type="text/javascript" src="/static/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(function(){
var cityChosen = getCookie('citychosen');
if(cityChosen!=null && cityChosen!=''){
var chosen = $('#choose option[value="'+cityChosen+'"]');
chosen.attr('selected',true);
$("#output").removeClass().addClass(cityChosen).html("You have selected this last time.<br />" + chosen.text());
}
$("#choose").change(function(){
var selected = $("#choose option:selected");
var output = "";
if(selected.val() != 0){
setCookie('citychosen',selected.val(),365);
output = "You just select this.<br />" + selected.text();
}
$("#output").removeClass().addClass(selected.val()).html(output);
});
});
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function dropCookie(name) {
createCookie(name,"",-1);
}
//]]>
</script>
<title>Select</title>
</head>
<body>
<select id="choose">
<option value="0">Select city</option>
<option value="city1">City 1</option>
<option value="city2">City 2</option>
<option value="city3">City 3</option>
<option value="city4">City 4</option>
</select>
<div id="output" class="default"></div>
</body>