Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  168] [ 1]  / answers: 1 / hits: 33112  / 7 Years ago, mon, april 17, 2017, 12:00:00

I have this https://jsfiddle.net/1zqgeq79/2/



This is the jquery I'm using to make the page refresh when a select has been changed and now I just need it to keep that selected option after the page loads.



       $('.ProductDetails select').change(function () {
location.reload();
});


Since I have multiple items I know a (this) will have to be used, but I'm still learning jquery. Thanks for the help!


More From » jquery

 Answers
6

Use sessionStorage instead of localStorage if you don't want to keep the data parmanently after closing the browser.



I replaced the code with:



var selectedProduct = sessionStorage.getItem(product);
if(selectedProduct != undefined || selectedProduct != null){
$(.ProductDetails select).first().find(:selected).removeAttr(selected);
$(.ProductDetails select).find(option).each(function () {
if ($(this).val() == selectedProduct) {
$(this).attr(selected, true);
}
});
}

$('.ProductDetails select').change(function () {
sessionStorage.setItem(product, $(.ProductDetails select).first().val());

location.reload();
});


Just go to: https://jsfiddle.net/1zqgeq79/3/



I did for first dropdown only.


[#58126] Friday, April 14, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
koltenb

Total Points: 276
Total Questions: 92
Total Answers: 101

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;