John01 Posted January 25, 2016 Share Posted January 25, 2016 (edited) 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 January 25, 2016 by John01 Quote Link to comment Share on other sites More sharing options...
requinix Posted January 25, 2016 Share Posted January 25, 2016 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>"; Quote Link to comment Share on other sites More sharing options...
Barand Posted January 25, 2016 Share Posted January 25, 2016 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" /> 2 Quote Link to comment 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.