Select List - State - PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <select name="state" id="form_state">
  2. <option value="-">State</option>
  3. <option<?=$state == 'other' ? ' selected="selected" : '' ;?> value="other">Other</option>
  4. <option<?=$state == 'AL' ? ' selected="selected" : '' ;?> value="AL">Alabama</option>
  5. <option<?=$state == 'AK' ? ' selected="selected" : '' ;?> value="AK">Alaska</option>
  6. <option<?=$state == 'AZ' ? ' selected="selected" : '' ;?> value="AZ">Arizona</option>
  7. <option<?=$state == 'AR' ? ' selected="selected" : '' ;?> value="AR">Arkansas</option>
  8. <option<?=$state == 'CA' ? ' selected="selected" : '' ;?> value="CA">California</option>
  9. <option<?=$state == 'CO' ? ' selected="selected" : '' ;?> value="CO">Colorado</option>
  10. <option<?=$state == 'CT' ? ' selected="selected" : '' ;?> value="CT">Connecticut</option>
  11. <option<?=$state == 'DE' ? ' selected="selected" : '' ;?> value="DE">Delaware</option>
  12. <option<?=$state == 'DC' ? ' selected="selected" : '' ;?> value="DC">District of Columbia</option>
  13. <option<?=$state == 'FL' ? ' selected="selected" : '' ;?> value="FL">Florida</option>
  14. <option<?=$state == 'GA' ? ' selected="selected" : '' ;?> value="GA">Georgia</option>
  15. <option<?=$state == 'HI' ? ' selected="selected" : '' ;?> value="HI">Hawaii</option>
  16. <option<?=$state == 'ID' ? ' selected="selected" : '' ;?> value="ID">Idaho</option>
  17. <option<?=$state == 'IL' ? ' selected="selected" : '' ;?> value="IL">Illinois</option>
  18. <option<?=$state == 'IN' ? ' selected="selected" : '' ;?> value="IN">Indiana</option>
  19. <option<?=$state == 'IA' ? ' selected="selected" : '' ;?> value="IA">Iowa</option>
  20. <option<?=$state == 'KS' ? ' selected="selected" : '' ;?> value="KS">Kansas</option>
  21. <option<?=$state == 'KY' ? ' selected="selected" : '' ;?> value="KY">Kentucky</option>
  22. <option<?=$state == 'LA' ? ' selected="selected" : '' ;?> value="LA">Louisiana</option>
  23. <option<?=$state == 'ME' ? ' selected="selected" : '' ;?> value="ME">Maine</option>
  24. <option<?=$state == 'MD' ? ' selected="selected" : '' ;?> value="MD">Maryland</option>
  25. <option<?=$state == 'MA' ? ' selected="selected" : '' ;?> value="MA">Massachusetts</option>
  26. <option<?=$state == 'MI' ? ' selected="selected" : '' ;?> value="MI">Michigan</option>
  27. <option<?=$state == 'MN' ? ' selected="selected" : '' ;?> value="MN">Minnesota</option>
  28. <option<?=$state == 'MS' ? ' selected="selected" : '' ;?> value="MS">Mississippi</option>
  29. <option<?=$state == 'MO' ? ' selected="selected" : '' ;?> value="MO">Missouri</option>
  30. <option<?=$state == 'MT' ? ' selected="selected" : '' ;?> value="MT">Montana</option>
  31. <option<?=$state == 'NV' ? ' selected="selected" : '' ;?> value="NV">Nevada</option>
  32. <option<?=$state == 'NH' ? ' selected="selected" : '' ;?> value="NH">New Hampshire</option>
  33. <option<?=$state == 'NJ' ? ' selected="selected" : '' ;?> value="NJ">New Jersey</option>
  34. <option<?=$state == 'NM' ? ' selected="selected" : '' ;?> value="NM">New Mexico</option>
  35. <option<?=$state == 'NY' ? ' selected="selected" : '' ;?> value="NY">New York</option>
  36. <option<?=$state == 'NC' ? ' selected="selected" : '' ;?> value="NC">North Carolina</option>
  37. <option<?=$state == 'ND' ? ' selected="selected" : '' ;?> value="ND">North Dakota</option>
  38. <option<?=$state == 'OH' ? ' selected="selected" : '' ;?> value="OH">Ohio</option>
  39. <option<?=$state == 'OK' ? ' selected="selected" : '' ;?> value="OK">Oklahoma</option>
  40. <option<?=$state == 'OR' ? ' selected="selected" : '' ;?> value="OR">Oregon</option>
  41. <option<?=$state == 'PA' ? ' selected="selected" : '' ;?> value="PA">Pennsylvania</option>
  42. <option<?=$state == 'RI' ? ' selected="selected" : '' ;?> value="RI">Rhode Island</option>
  43. <option<?=$state == 'SC' ? ' selected="selected" : '' ;?> value="SC">South Carolina</option>
  44. <option<?=$state == 'SD' ? ' selected="selected" : '' ;?> value="SD">South Dakota</option>
  45. <option<?=$state == 'TN' ? ' selected="selected" : '' ;?> value="TN">Tennessee</option>
  46. <option<?=$state == 'TX' ? ' selected="selected" : '' ;?> value="TX">Texas</option>
  47. <option<?=$state == 'UT' ? ' selected="selected" : '' ;?> value="UT">Utah</option>
  48. <option<?=$state == 'VT' ? ' selected="selected" : '' ;?> value="VT">Vermont</option>
  49. <option<?=$state == 'VA' ? ' selected="selected" : '' ;?> value="VA">Virginia</option>
  50. <option<?=$state == 'WA' ? ' selected="selected" : '' ;?> value="WA">Washington</option>
  51. <option<?=$state == 'WV' ? ' selected="selected" : '' ;?> value="WV">West Virginia</option>
  52. <option<?=$state == 'WI' ? ' selected="selected" : '' ;?> value="WI">Wisconsin</option>
  53. <option<?=$state == 'WY' ? ' selected="selected" : '' ;?> value="WY">Wyoming</option>
  54. </select>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.