Jump to content

Hours:Minutes drop downs


John01

Recommended Posts

Hi

 

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 change the input type above into two drop downs; one each for hours and minutes and then join the user entered hh and mm values into a single hh:mm value?

 

Thanks

 

Regards

 
Link to comment
Share on other sites

You have got an elegant solution for this from your other post.

 

But, if you want to get hours and minutes into separate dropdown, we can do it something like this,

<select name="hour">
<?php
 for ($i=0; $i<=23; $i++){
   $i = sprintf('%02d', $i);
   echo "<option value='".$i."'>" . $i ."</option>\n";
 }
?>
</select>

<select name="minutes">
<?php
 for ($i=0; $i<=59; $i++){
   $i = sprintf('%02d', $i);
   echo "<option value='".$i."'>" . $i ."</option>\n";
 }
?>
</select>
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.