mrmark01 Posted August 17, 2009 Share Posted August 17, 2009 Hi guys, I'm having real trouble trying to do something real simple... I'm trying to generate a drop down menu box which allows a user to select a time (24 hr clock). I want the contents to be in the form of 0100, 0200, 0300, ... , 2300, 2400. The result of the code below is a drop down menu box is created but all the menu items are empty, there's just 24 blank entries. The call <td class="main"><?php echo tep_draw_pull_down_time('arrival_times') . ' ' . (tep_not_null(ENTRY_TIME_OF_ARRIVAL_TEXT) ? '<span class="inputRequirement">' . ENTRY_TIME_OF_ARRIVAL_TEXT . '</span>': '');?> </td> The methods function tep_draw_pull_down_time($name='') { $times = array(); $i=01; while($i<25) { $times[$i] = $i * 100; } $fields = temp_draw_pull_down_menu($name, $times, ''); return fields; } function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) { global $HTTP_GET_VARS, $HTTP_POST_VARS; $field = '<select name="' . tep_output_string($name) . '"'; if (tep_not_null($parameters)) $field .= ' ' . $parameters; $field .= '>'; if (empty($default) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) { if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) { $default = stripslashes($HTTP_GET_VARS[$name]); } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) { $default = stripslashes($HTTP_POST_VARS[$name]); } } for ($i=0, $n=sizeof($values); $i<$n; $i++) { $field .= '<option value="' . tep_output_string($values[$i]['id']) . '"'; if ($default == $values[$i]['id']) { $field .= ' SELECTED'; } $field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>'; } $field .= '</select>'; if ($required == true) $field .= TEXT_FIELD_REQUIRED; return $field; } I would be most grateful if anyone could aid me in a solution to finding this problem. Thanks in advance, Link to comment https://forums.phpfreaks.com/topic/170680-24hr-select-drop-down-box/ Share on other sites More sharing options...
rhodesa Posted August 17, 2009 Share Posted August 17, 2009 try function tep_draw_pull_down_time($name='') { $times = array(); for($i=1;$i<25;$i++) { $times[$i] = sprintf('%04d',$i * 100); } $fields = temp_draw_pull_down_menu($name, $times, ''); return fields; } Link to comment https://forums.phpfreaks.com/topic/170680-24hr-select-drop-down-box/#findComment-900286 Share on other sites More sharing options...
mrmark01 Posted August 18, 2009 Author Share Posted August 18, 2009 Thanks for your reply rhodesa. I've tried your function and it's a bit better then what I got but it's still not working correctly. The output is a drop down menu containing the values 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2 Any other ideas? Link to comment https://forums.phpfreaks.com/topic/170680-24hr-select-drop-down-box/#findComment-900787 Share on other sites More sharing options...
rhodesa Posted August 18, 2009 Share Posted August 18, 2009 small modification to the function...it should be: function tep_draw_pull_down_time($name='') { $times = array(); for($i=1;$i<25;$i++) { $times[] = array( 'id' => sprintf('%04d',$i * 100), 'text' => sprintf('%04d',$i * 100), ); } $fields = tep_draw_pull_down_menu($name, $times, ''); return $fields; } also...what is the code for the tep_output_string() and tep_not_null() functions? Link to comment https://forums.phpfreaks.com/topic/170680-24hr-select-drop-down-box/#findComment-900866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.