I have a form with a bunch of <select> fields - most of these have only about 4 <options>. I am first writing the PHP validation and this checks if the user has selected an <option> then it adds the attribute of "selected" to that option. However there are a lot of if statements (the way I am doing it). I have a state field with 50 of the US states and I am wary about adding 50 unnecessary if statements. Guidance is appreciated.
Here's what I have:
Code PHP:
Code PHP:<option value="Alaska" <?php if($state=="Alaska") echo(" selected=\"selected\"");?>>Alaska</option>
First off, writing all those statements for each state would be a pain, second I am not sure about all those if statements. How would a pro handle this? Teach me!



Reply With Quote





Bookmarks