user2848031
user2848031

Reputation: 227

sessionStorage not working in IE and Chrome

On page load I am storing a value in the session and again getting back after loading the page. But IE and Chrome are not returning back the session storage value.

On Firefox it is working as expected.

Here is the code:

<select id="myDropDownList" name="myDropDownList" class="custom-select my-1 mr-sm-2">
    <option value="one">one</option>
    <option value="two">twoCode</option>
    <option value="three">three</option>
</select>

Javascript:

$('#myDropDownList').change(function() {
    var dropVal = $(this).val();
    sessionStorage.setItem("SelectedItem", dropVal);
    location.reload();
});

$("#mydropdownlist").val(sessionStorage.getItem("SelectedItem"));

Upvotes: 0

Views: 2717

Answers (1)

Matti Price
Matti Price

Reputation: 3551

Changing to the proper capitalization seems to fix it for my test on Chrome.

Change to:

 $("#myDropDownList").val(sessionStorage.getItem("SelectedItem"));

Expanding on why a bit. Looks like JQuery uses appropriate browser methods if available, and those tend to be case sensitive. I guess it isn't in Firefox though.

Upvotes: 4

Related Questions