user978122
user978122

Reputation: 5761

Implementing a drop-down combobox in PHP

I am trying to implement a hour / minute / (am/pm) control. Something similar to what Hotmail has under their calendar. Does anyone have an idea where to start?

The control, visually, is a textfield; however, clicking it allows you to either enter in a time via typing, or selecting a time from a dropdownlist (which appears underneath the textfield).

Thanks.

Upvotes: 1

Views: 201

Answers (3)

Deeps23
Deeps23

Reputation: 51

This is for generating time in Combo box, which includes minutes.

$times = array();

$start = strtotime('8:00am');
$finish = strtotime('12:00am tomorrow');

while($start <= $finish) {
    $times[] = date('g.ia', $start);
    $start += strtotime('+30 min', 0);
}

var_dump($times);

I hope this helps you. Thanks.

Upvotes: 0

Sampson
Sampson

Reputation: 268462

This isn't something you would do with PHP, but rather with a client-side technology like jQueryUI. I would suggest you look into the $.datepicker() plugin. This plugin will do what you're asking right out of the box with a single line of JavaScript:

$("#mydate").datepicker();

Which will result in the following:

enter image description here

There are a great deal of options and configurations that you can take advantage of to really customize the data the user can select, as well as how the user interacts with the widget in general.

See the documentation for further info: http://jqueryui.com/demos/datepicker/

Upvotes: 1

g13n
g13n

Reputation: 3246

This is not possible entirely in PHP, you need to use JavaScript.

Any reason you cannot use a jQuery or YUI widget?

If you cannot for some reason, you need to start off by binding onmousedown event for the textbox and have it draw either a drop-down menu with the date/time.

Hope that helps to give you some direction.

Upvotes: 0

Related Questions