-1

I have a form in HTML which is as follows:

<select name="color_type">
    <option value="red" selected><?php echo __( 'red', 'my-color' );?></option>
    <option value="blue" selected><?php echo __( 'blue', 'my-color' );?></option>
    <option value="white" selected><?php echo __( 'white', 'my-color' );?></option>
</select>

When the form is submitted, how do I get it to retain the current selection? for example, if the user selects 'blue' when the page is reloaded, the dropdown options has the placeholder 'red' instead of the chosen option, even though 'blue' is active.

I am trying to avoid lots of if else statements as there will be around 50 options in the end.

Any help would be appreciated!

azibom
  • 1,769
  • 1
  • 7
  • 21
LBarc
  • 27
  • 6

1 Answers1

0

You can find an answer to the question using JavaScript here: Keep values selected after form submission

Also found this answer using php: PHP keep dropdown value after submit