<select id="networkCapacityList" name="networkCapacityList" class="long select2-hidden-accessible" tabindex="-1" aria-hidden="true">
<option value="">Please Select</option>
<option value="221">Business 1</option>
<option value="456">Business 2</option>
<option value="843">Business 3</option>
$('#networkCapacityList').on('change', function () {
var businessID = $(this).val();
var holdBusinessID = localStorage.setItem("businessID", businessID);
location.reload();
});
getbusinessID = localStorage.getItem("businessID");
$("#networkCapacityList").find("[value="+getbusinessID+"]").prop("selected", true);
//$("#networkCapacityList option[value="+getbusinessID+"]").prop('selected', true);
//$('#networkCapacityList option').filter('[value="' + getbusinessID + '"]').prop('selected', 'selected');
I am getting a business id from a user action. I hold this data in a localStorage object. I have to reload the page for some functional issues. Then I can get the business id.
After reloading the location, the browser loses all user actions. So, the dropdown list shows "Please select" as a default value. I would like to pre-set the value on the select. I have tried all available options without success. I get the business Id correctly from the localstorage.
For example:
$("#networkCapacityList").find("[value="+getbusinessID+"]").prop("selected", true);
$("#networkCapacityList").find("[value="+221+"]").prop("selected", true);
Any helps would highly be appreciated.