Jump to content
John01

Hours:Minutes drop downs

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

 

Share this post


Link to post
Share on other sites

Use two <select> inputs with the relevant hours and minutes as <options>. Then on the page that receives the data, concatenate the two values with a colon.

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

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.