Consider:
<form method="get" action=""> <select name="name"> <option value="a">a</option> <option value="b">b</option> </select> <select name="location"> <option value="x">x</option> <option value="y">y</option> </select> <input type="submit" value="Submit" class="submit" /> </form>
On submitting the form, how do I make sure that the selected values remain selected in the dropdowns? This form is inside WordPress (PHP).
To avoid many if-else structures, let JavaScript do the trick automatically:
<select name="name" id="name"> <option value="a">a</option> <option value="b">b</option> </select> <script type="text/javascript"> document.getElementById('name').value = "<?php echo $_GET['name'];?>"; </script> <select name="location" id="location"> <option value="x">x</option> <option value="y">y</option> </select> <script type="text/javascript"> document.getElementById('location').value = "<?php echo $_GET['location'];?>"; </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With