Jump to content

24hr select drop down box


mrmark01

Recommended Posts

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('"' => '"', '\'' => '&#039;', '<' => '<', '>' => '>')) . '</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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.