With .php and javascript how could I leave selected the option that the user selected in a form, after giving the input button to process the fields?
You get the value you selected, but I do not know how to get to the option and setAttribute selected selected
<select id="id_of_select">
<option></option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<button id="btn">Show selected</button>
<script>
function show_selected() {
var selector = document.getElementById('selectedIMon1');
var value = selector[selector.selectedIndex].value;
var index = selector[selector.selectedIndex].index;
alert(value);
}
document.getElementById('btn').addEventListener('click', show_selected);
;
</script>
Greetings