Retains Form Select With sessionStorage HTML5

After selecting an option you can refresh the page and the option will remain the selected option. This also works with localStorage

by Colin Soderstrom

HTML

<select id="rtnRfsh">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>

JavaScript

$(document).ready(function() {

	//Retains selection after page refresh
	$("#rtnRfsh").change(function() {
		sessionStorage.ocupation=$("#rtnRfsh").val();
	});
	$("#rtnRfsh").val(sessionStorage.ocupation);
	
});