Reputation: 49
I'm need to keep selected values persistent when the page reloads. I'm using a multiselect plugin with jQuery for a dropdown selection menu. Is this possible? I don't know a whole lot about this, so if I sound dumb, sorry. :)
<select multiple="multiple" style="width: 135px;" name="platform[]" id="platform">
<option value="platform_1">Platform 1</option>
<option value="platform_2">Platform 2</option>
</select>
<select id="2" multiple="multiple" style="width: 165px;" name="features[]" id="features">
<optgroup label="Group One">
<option value="feature_1">Feature 1</option>
<option value="feature_2">Feature 2</option>
<option value="feature_3">Feature 3</option>
<option value="feature_4">Feature 4</option>
<option value="feature_5">Feature 5</option>
<optgroup label="Group Two">
<option value="feature_6">Feature 6</option>
<option value="feature_7">Feature 7</option>
<option value="feature_8">Feature 8</option>
</select>
Upvotes: 2
Views: 699
Reputation: 84
here is a example of what you might need:
$("#platform").val(getCookie("platform"));
$("#2").val(getCookie("feature"));
$("#platform option").click(function(){
document.cookie = "platform="+$(this).val();
});
$("#2 option").click(function(){
document.cookie = "feature="+$(this).val();
});
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
Upvotes: 3