dfowler Posted April 3, 2008 Share Posted April 3, 2008 Hey guys, I am reworking some code that somebody else wrote. It basically gets time for an order. However, I am suppose to add 15 minute intervals onto the form, and I have no clue how to process this correctly with what he has already written. Here is the form: <script type="text/javascript"> function toggleTimeSelects() { orderforsel = document.getElementById('order_for'); timesel = document.getElementById('time'); ampmsel = document.getElementById('ampm'); if (orderforsel.value == "now") { timesel.disabled = true; ampmsel.disabled = true; } else if (orderforsel.value == '') { timesel.disabled = true; ampmsel.disabled = true; } else { timesel.disabled = false; ampmsel.disabled = false; } } </script> <select name="order_for" id="order_for" onchange="javascript:toggleTimeSelects()"> <option value="now">Now</option> <option value="today">Today at:</option> <option value="tomorrow">Tomorrow at:</option> </select> <select name="time" id="time" disabled> <?php for ( $counter = 1; $counter <= 12; $counter += 1) { ?> <option value="<?php echo $counter; ?>"><?php echo $counter; ?></option> <?php } ?> </select> <select name="ampm" id="ampm" disabled> <option value="am">AM</option> <option value="pm">PM</option> </select> Here is the code that processes the form: $order_for = $_POST['order_for']; $time = $_POST['time']; $ampm = $_POST['ampm']; if ($order_for == 'now') { $forDate = date('Y-m-d H:i:s'); } else if ($order_for == 'today') { $forDate = date('Y-m-d',time() + 60*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':00:00'; } else { $forDate = date('Y-m-d',time() + 12*60*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':00:00'; } Quote Link to comment https://forums.phpfreaks.com/topic/99374-help-with-time/ Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 Okay this is soo very untested <select name="time" id="time" disabled> <?php for ( $counter = 1; $counter <= 12; $counter += 1) { ?> <option value="<?php echo $counter; ?>"><?php echo $counter; ?></option> <?php } ?> </select> <!-- Add --> <select name="mins" id="mins" disabled> <?php for ( $counter = 0; $counter <= 45; $counter += 15) { ?> <option value="<?php echo $counter; ?>"><?php echo $counter; ?></option> <?php } ?> </select> <!-- done adding --> <select name="ampm" id="ampm" disabled> <option value="am">AM</option> <option value="pm">PM</option> </select> $order_for = $_POST['order_for']; $time = $_POST['time']; $min = $_POST['mins']; //Add $ampm = $_POST['ampm']; if ($order_for == 'now') { $forDate = date('Y-m-d H:i:s'); } else if ($order_for == 'today') { $forDate = date('Y-m-d',time() + (60+$min)*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':$min:00'; //Edit } else { $forDate = date('Y-m-d',time() + 12*(60+$min)*60).' '.($ampm == 'am' ? str_pad($time,2,'0',STR_PAD_LEFT) : ($time + 12)).':$min:00'; //Edit } Quote Link to comment https://forums.phpfreaks.com/topic/99374-help-with-time/#findComment-508467 Share on other sites More sharing options...
dfowler Posted April 3, 2008 Author Share Posted April 3, 2008 Yeah, I ended up doing something extremely similar to this. I literally just stared at it for awhile and then it hit me how easy it actually was to do. As you did, just a few tweaks here and there. Thanks for you help! Quote Link to comment https://forums.phpfreaks.com/topic/99374-help-with-time/#findComment-508595 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.