Jump to content

Timepicker onClose: not trigering a calculate function.


ztimer

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.