John01 Posted February 2, 2016 Share Posted February 2, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300712-hoursminutes-drop-downs/ Share on other sites More sharing options...
Psycho Posted February 2, 2016 Share Posted February 2, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300712-hoursminutes-drop-downs/#findComment-1530670 Share on other sites More sharing options...
thara Posted February 2, 2016 Share Posted February 2, 2016 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> Quote Link to comment https://forums.phpfreaks.com/topic/300712-hoursminutes-drop-downs/#findComment-1530672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.