<select id="form">
<option value="1" >1 </option>
<option value="2" >2 </option>
<option value="3" >3 </option>
</select>
<button id='next'>Next</button>
<script>
var select2 = document.getElementById("form");
var lastselected2 = localStorage.getItem('select2');
document.getElementById('next')
.addEventListener('click', function(){
lastselected2 = parseInt(lastselected2) + 1;
});
if(lastselected2) {
select2.value = lastselected2;
}
select2.onchange = function () {
lastselected2 = select2.options[select2.selectedIndex].value;
console.log(lastselected2);
localStorage.setItem('select2', lastselected2);
}
</script>
I've this code that saves the selected of the dropdown and I wanted to add a button that can select the next option of the dropdown.