Skip to content

Instantly share code, notes, and snippets.

@alexfurr
Created February 3, 2020 15:36
Show Gist options
  • Save alexfurr/677db3e2a284eb445b13d874801783e7 to your computer and use it in GitHub Desktop.
Save alexfurr/677db3e2a284eb445b13d874801783e7 to your computer and use it in GitHub Desktop.
Draw TimePicker in PHP
function drawTimepicker($hourValue="", $minValue="",$hourID="myHour", $minID="myMin")
{
if($hourValue==""){$hourValue=10;}
$i=1;
$html = '';
$html.='<select name="'.$hourID.'" id="'.$hourID.'">';
while($i<=23)
{
$iString = $i;
if($i<10){$iString = '0'.$i;}
$html.='<option value="'.$iString.'"';
if($hourValue==$iString){$html.= ' selected ';}
$html.='>'.$iString.'</option>';
$i++;
}
$html.='</select>';
$i=0;
$html.='<select name="'.$minID.'" id="'.$minID.'">';
while($i<=59)
{
$iValue=$i;
if($iValue<10){$iValue = '0'.$i;}
$html.='<option value="'.$iValue.'"';
if($minValue==$iValue){$html.= ' selected ';}
$html.= '>'.$iValue.'</option>';
$i = $i+5;
}
$html.='</select>';
//$html.='<select name="'.$minID.'_AMPM" id="'.$minID.'_AMPM">';
//$html.='<option value="AM">AM</option>';
//$html.='<option value="PM">PM</option>';
//$html.='</select>';
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment