Return to Snippet

Revision: 18238
at September 24, 2009 03:57 by chchrist


Updated Code
function timeSelect($name,$mode,$selected) {
						
     if($mode) {
	$mode = 24;
     } else {
	$mode = 60;
     }
						
     echo '<select name="'.$name.'" >';
     echo '<option value="-1">--</option>';
						
     for ($i=0;$i<$mode;$i++) {
      if($i <=9) {
	$i = "0".$i;
      }
							
      if($i == $selected) {
	echo '<option selected="selected" value="'.$i.'" >'.$i.'</option>';				
      } else {
	echo '<option value="'.$i.'" >'.$i.'</option>';
      }
     }
     echo '</select>';
}

// use like

timeSelect("event_start_hour",true,$_POST['event_start_hour']);

timeSelect("event_start_minute",false,$_POST['event_start_hour']);

Revision: 18237
at September 24, 2009 03:57 by chchrist


Updated Code
function timeSelect($name,$mode,$selected) {
						
     if($mode) {
	$mode = 24;
     } else {
	$mode = 60;
     }
						
     echo '<select name="'.$name.'" >';
     echo '<option value="-1">--</option>';
						
     for ($i=0;$i<$mode;$i++) {
      if($i <=9) {
	$i = "0".$i;
      }
							
      if($i == $selected) {
	echo '<option selected="selected" value="'.$i.'" >'.$i.'</option>';				
      } else {
	echo '<option value="'.$i.'" >'.$i.'</option>';
      }
     }
     echo '</select>';
}

// use like

timeSelect("event_start_hour",false,$_POST['event_start_hour']);

Revision: 18236
at September 24, 2009 03:54 by chchrist


Initial Code
function timeSelect($name,$mode,$selected) {
						
						if($mode) {
							$mode = 24;
						} else {
							$mode = 60;
						}
						
						echo '<select name="'.$name.'" >';
						echo '<option value="-1">--</option>';
						
						for ($i=0;$i<$mode;$i++) {
							if($i <=9) {
								$i = "0".$i;
							}
							
							if($i == $selected) {
								echo '<option selected="selected" value="'.$i.'" >'.$i.'</option>';				
							} else {
								echo '<option value="'.$i.'" >'.$i.'</option>';
							}
						}
						echo '</select>';
					}

// use like

timeSelect("event_start_hour",false,$_POST['event_start_hour']);

Initial URL

                                

Initial Description
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.

Initial Title
Php generated Hour/Minute Dropdown

Initial Tags
php

Initial Language
PHP