Php generated Hour/Minute Dropdown


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

A simple function that generates a select drop down. It takes 3 values. The select name ,the mode (true for hours / false for minutes) and the selected option.


Copy this code and paste it in your HTML
  1. function timeSelect($name,$mode,$selected) {
  2.  
  3. if($mode) {
  4. $mode = 24;
  5. } else {
  6. $mode = 60;
  7. }
  8.  
  9. echo '<select name="'.$name.'" >';
  10. echo '<option value="-1">--</option>';
  11.  
  12. for ($i=0;$i<$mode;$i++) {
  13. if($i <=9) {
  14. $i = "0".$i;
  15. }
  16.  
  17. if($i == $selected) {
  18. echo '<option selected="selected" value="'.$i.'" >'.$i.'</option>';
  19. } else {
  20. echo '<option value="'.$i.'" >'.$i.'</option>';
  21. }
  22. }
  23. echo '</select>';
  24. }
  25.  
  26. // use like
  27.  
  28. timeSelect("event_start_hour",true,$_POST['event_start_hour']);
  29.  
  30. timeSelect("event_start_minute",false,$_POST['event_start_hour']);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.