Advertisement
NiTeWuRX

Mark Selected on Dropdown based on Variable

Jun 6th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. Mark Selected on Dropdown based on Variable
  2.  
  3. You could pull info from a GET/POST or MySQl query
  4.  
  5. <?
  6. //I prefer to assign to a variable and then compare
  7. $EyeColor = $_GET['EyeColor'];
  8. //for testing - comment out when not needed
  9. echo $EyeColor;
  10. ?>
  11.  
  12. <select name="EyeColor">
  13. <option value=""<?=$EyeColor == '' ? ' selected="selected"' : '';?>> </option>
  14. <option value="blue"<?=$EyeColor == 'blue' ? ' selected="selected"' : '';?>>Blue</option>
  15. <option value="brown"<?=$EyeColor == 'brown' ? ' selected="selected"' : '';?>>Brown</option>
  16. </select>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement