user1667178
user1667178

Reputation: 23

jQuery select value set issue

For the life of me, I cannot figure this out. Hopefully some of you experts can help me out :> I've tried several approaches I've found on here..however, I must be placing the code wrong as I cannot seem to set the value properly.

What I wish to happen is, the user selects a region in the drop down,which in turn sets a cookie. Depending on the cookie, the user will be redirected to a specific page. I seem to have set/detected the cookie properly, but once the user reaches the new page, I want the region dropdown to have the current region "selected" so the user knows they are in the right region.. how do I set the selected value when the cookie is detected as a specific region?

here is my code so far:

<select id="regionSelect">
<option id="aus" value="aus">Australia</option>
<option id="fr" value="fr">France</option>
<option id="ger" value="ger">Germany</option>
<option id="usa" value="usa">USA</option>
</select>

<script>
$('#regionSelect').change(function() {

   $.cookie('hrregion', $(this).val(), {expires: 365});

if ($.cookie('hrregion') == "aus") {
       window.location.href = "australia.aspx";  
}

if ($.cookie('hrregion') == "fr") {
       window.location.href = "france.aspx";  
}

if ($.cookie('hrregion') == "ger") { 
        window.location.href = "germany.aspx";        
}

if ($.cookie('hrregion') == "usa") {
       window.location.href = "usa.aspx";  
}
</script>

Upvotes: 0

Views: 568

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

Before the end of your script, add:

$("#regionSelect").val($.cookie('hrregion'));

Upvotes: 5

Related Questions