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
Share on other sites

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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.