Results 1 to 7 of 7
Oct 10, 2012, 17:50 #1
- Join Date
- Jan 2005
- 1 Post(s)
- 1 Thread(s)
Maintaining the Select option when validating a form
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:
<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!