First, I want to apologize for the ambiguous title 🙂
Second, I’m a novice with jQuery.
I have a drop down with two values (“taget1” and “target2”). On page load, I’m setting the localStorage with a URL for each target (target1=google.com and target2=gmail.com).
When the drop down changes, I set a “lastSelection” var in localStorage (lastSelection=target2).
Now, I also want to get the relevant URL from localStorage. So when I change to “target2” I want to get the saved URL from localStorage. Instead of using an “if”, I thought I can use the val() of the drop down.
This did not work:
var url = localStorage.getItem([lastSelection])
How can I use the value of lastSelection to get a result like localStorage.getItem('target2')?
It seems ‘target1’ and ‘target2’ are text that appear in the dropdown. You could use:
If they refer to the actual value of the options instead of text, then
Now you can use selectedText or selectedValue, which ever one you want as a parameter to get stuff from local storage.