The key line in the script isvar tmp = $(this).parent().find('select').val();
and tmp
returns, for example, "s1"
(including the quotes) as seen in the console, which is what is expected. tmp will have different values depending on what is picked on the page.
But sessionStorage.tmp = 2
created a key:value pair of ``tmp:2, nots1:2
.
How do I create a sessionStorage object s1
with value 2
?
Seems like this should be simple. I tried tmp = tmp.toString(); and a million other things, but I'm too much of a newbie to figure this out. Thanks for any help.
If you want to use a string
as a property name you'll have to use a construct like this:
sessionStorage[tmp] = 2
This seems to be called bracket notation you can find more details about it HERE