function saveOptions() { var timeformat; if (document.getElementById('t24').checked) timeformat = 24; else if (document.getElementById('t12').checked) timeformat = 12; else return; localStorage['timeformat'] = timeformat; var status = document.getElementById('status'); status.innerHTML = 'Options saved'; setTimeout(function() { status.innerHTML = '' }, 2000); } function restoreOptions() { // default to 24 for both unset and invalid var timeformat = localStorage['timeformat'] || 24; var option = document.getElementById('t' + timeformat) || document.getElementById('t24'); option.checked = true; } function startOptions() { restoreOptions(); document.querySelector('#save').addEventListener('click', saveOptions); } window.onload = startOptions;