When I return to a user because of errors in PHP, I can give the textboxes a value with something like value = "<?php if(isset($_POST['abc'])){echo $_POST['abc'];}. How do I do the equivalent with a <select> combobox?
When I return to a user because of errors in PHP, I can give
Share
It depends a bit on what you mean by
refreshed.If you mean a literal refresh / reload of the page without any posting, you can use javascript to store the value when it is changed and load that value when the page is refreshed / loaded. Your storing options vary from cookies and local storage on the visitors computer to server-side storage using ajax.
If you are talking about using previously saved / posted values when you load the same page at a later time, it’s a different story, although the ajax approach would work as well there (might not be necessary though).
Edit: Based on your edit, you need to add
selected="selected"to the previously selected option.So in the loop that builds your select options (assuming a loop), you do something like: