ztimer Posted October 19, 2011 Share Posted October 19, 2011 Hi. I have whipped up some time calculation script using numerous other scripts and everything is working like it should i just need to click on the second input textbox after using the timepicker to select time that will insert itself to the text box. What i found is that i could use a trigger after the selection has been done what is wrong and i dont understand is why is it not triggering the function. Code below. timedifference.php <?php function get_time_difference( $start, $end ) { $uts['start'] = strtotime( $start ); $uts['end'] = strtotime( $end ); if( $uts['start']!==-1 && $uts['end']!==-1 ) { if( $uts['end'] >= $uts['start'] ) { $diff = $uts['end'] - $uts['start']; if( $days=intval((floor($diff/86400))) ) $diff = $diff % 86400; if( $hours=intval((floor($diff/3600))) ) $diff = $diff % 3600; if( $minutes=intval((floor($diff/60))) ) $diff = $diff % 60; $diff = intval( $diff ); return( array('success'=>1, 'days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) ); //return( array('success'=>1, 'days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) ); } else { return(array('success'=>0, 'reason'=>'Algus kellaaeg on varasem kui lopp')); } } else { return(array('success'=>0, 'reason'=>'Vigane kellaaeg')); } } $start = $_GET['s']; $end = $_GET['e']; echo json_encode(get_time_difference( $start, $end )); ?> main.php half of the code. <script type="text/javascript"> $(document).ready(function() { $("<?php echo "#".$end_time; ?>").blur(function(){ var start_time = $("<?php echo "#".$start_time; ?>").val(); var end_time = $("<?php echo "#".$end_time; ?>").val(); $.getJSON("include/timedifference.php?s="+start_time+"&e="+end_time, function(data){ var success = data.success; if (success == 1) { $("<?php echo "#".$difference; ?>" ).val(data.hours + " h " + data.minutes + " m "); if (data.hours + data.minutes/60 >= 6){ $("<?php echo "#".$hours_difference; ?>").val(data.hours + data.minutes/60 - 0.5); }else { $("<?php echo "#".$hours_difference; ?>").val(data.hours + data.minutes/60); } } else { $("#message").text("Viga! " + data.reason); } }) }); }); </script> <script type="text/javascript"> $(function(){ $("<?php echo "#".$start_time; ?>").timepicker({ <?php If($row['time_start'] == null){ ?> timeFormat: 'hh:mm:ss', hourMin: 1, hourMax: 23 <?php } ?> <?php If($row['time_start'] == '10:00:00'){ ?> timeFormat: 'hh:mm:ss', hourGrid: 1, minuteGrid: 10, hourMin: 10, hourMax: 17 <?php } ?> <?php If($row['time_start'] == '08:00:00'){ ?> timeFormat: 'hh:mm:ss', hourGrid: 1, minuteGrid: 10, hourMin: 8, hourMax: 17, <?php } ?> }); $("<?php echo "#".$end_time; ?>").timepicker({ <?php If($row['time_stop'] == null){ ?> timeFormat: 'hh:mm:ss', hourMin: 8, hourMax: 17 <?php } ?> <?php If($row['time_stop'] == '17:30:00'){ ?> timeFormat: 'hh:mm:ss', hourGrid: 1, minuteGrid: 10, hourMin: 10, hourMax: 17 <?php } ?> <?php If($row['time_stop'] == '19:00:00'){ ?> timeFormat: 'hh:mm:ss', hourGrid: 1, minuteGrid: 10, hourMin: 10, hourMax: 19, onClose: function() { get_time_difference( start_time, end_time ); <--// here is the problem.... } <?php } ?> }); }); </script> <?php echo "<td><input type='text' name='$start_time' id='$start_time' onmouseout=''/></td>"; echo "<td><input type='text' name='$end_time' id='$end_time' onmouseout=''/></td>"; echo "<td><input id='".$hours_difference."' type='text' class='amt' value='' name='".$hours_difference."'/></td>"; ?> Please please help if you find what i have done wrong Link to comment https://forums.phpfreaks.com/topic/249382-timepicker-onclose-not-trigering-a-calculate-function/ Share on other sites More sharing options...
ztimer Posted October 19, 2011 Author Share Posted October 19, 2011 the problem is here. How to call the function correctly? <?php If($row['time_stop'] == '19:00:00'){ ?> timeFormat: 'hh:mm:ss', hourGrid: 1, minuteGrid: 10, hourMin: 10, hourMax: 19, onClose: function() { get_time_difference( start_time, end_time ); <--// here is the problem.... } <?php } ?> Link to comment https://forums.phpfreaks.com/topic/249382-timepicker-onclose-not-trigering-a-calculate-function/#findComment-1280491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.