Jump to content

Recommended Posts

Hi

 

Total newbie to PHP. I have below code to allow entry of time (hh:mm);

<div id="username-wrapper" class="forminput_wrapper">
	<input type="text" name="fromtime[]" value="" placeholder="From Time (hh:mm)" class="forminput" />
</div>

How can I turn the input type into a drop down with predefined time values (01:00, 01:15, 01:30 etc) as well as letting user enter any time they want?

 

 

Thanks

 

Regards

Edited by John01
Link to comment
https://forums.phpfreaks.com/topic/300652-time-drop-down-in-form/
Share on other sites

How do you want the user to decide? Do you want them to give them both options at once? Have some sort of "custom" item in the list?

 

For the list itself, a simple for loop will do:

echo "<select>";
for ($m = 0; $m <= 24; $m += 0.25) {
	$hhmm = sprintf("%02u:%02u", floor($m), (60 * $m) % 60);
	echo "<option value='{$hhmm}'>{$hhmm}</option>";
}
echo "</select>";

You could use a <datalist>..</datalist>

<datalist id='timeoptions'>
    <option>1:00</option>
    <option>1:15</option>
    <option>1:30</option>
    <option>1:45</option>
    <option>2:00</option>
    <option>2:15</option>
    <option>2:30</option>
</datalist>

<input type="text" name="fromtime[]" value="" placeholder="From Time (hh:mm)" class="forminput" list="timeoptions" />

  • Like 2
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.