forms
|keep selected combobox
| see demonstration of keep selected comboboxoften you need to "remember" what a user inputs in a form.
that's not a problem with textfields, but with selectboxes it's a bit harder...
full source of keep selected combobox [ line 1 - 24 ] | download keep selected combobox
| 1 | <? |
| 2 | // you need the values of your combobox in an array |
| 3 | $values = array('us','de','uk','fr','xx'); |
| 4 | echo ' |
| 5 | <form method="post" action="'.$_SERVER['PHP_SELF'].'"> |
| 6 | <select name="country">'; |
| 7 | for($x = 0; $x < count($values); $x++) |
| 8 | { |
| 9 | // write "selected" if the value matches the one posted |
| 10 | if($values[$x] == $_POST['country']) |
| 11 | { |
| 12 | $selected = ' selected'; |
| 13 | }else{ |
| 14 | $selected = ''; |
| 15 | } |
| 16 | // print the option |
| 17 | echo ' |
| 18 | <option value="'.$values[$x].'"'.$selected.'>'.$values[$x].'</option>'; |
| 19 | } |
| 20 | echo ' |
| 21 | </select> |
| 22 | <input type="submit" value="check it out"> |
| 23 | </form>'; |
| 24 | ?> |
20 hits by 8 users in the last 30 minutes.