Posted By

davidsword on 10/05/08


Tagged

select php html array


Versions (?)

Pre-Select HTML Select Form


 / Published in: PHP
 

URL: http://davidsword.ca/?library

Pre-selects an html form with a requested value... ie; editing a form from a database

  1. //applicable values
  2. $values = array('value1', 'value2', 'value3', 'value4', 'value5');
  3. //get current value
  4. $val = $_REQUEST['value'];
  5. //print html selection
  6. echo "<select>";
  7. foreach($values as $v) {
  8. $s = ($val == $v) ? " selected='selected'" : null;
  9. echo "<option$s>$v</option>\n",
  10. }
  11. echo "</select>";

Report this snippet  

You need to login to post a comment.