DateTime picker calculates price


March 2019


83 time


I'm using 2 Inline DateTimePicker ( to calculate the difference between 2 DateTimes. As the result I get difference in hours and then I multiply them with my static price. The main problem is that I use submit form and after every calculation my DateTime picker resets.

How I'm able to do the same calculation without refreshing the page (via ajax), that calculates price directly by selecting the values?

Thank you.


2 answers


You could post the input elements values in your form. Then when the server answers the post you fill the input elements on the server.

Then when the client loads and you apply

jQuery('#datetimepicker').datetimepicker();//From their site

The time picker should get its pre form post value.

Then you can calculate what you need, if both input elements has values

var $timepicker1 = jQuery('#datetimepicker1').datetimepicker();
var $timepicker2 = jQuery('#datetimepicker2').datetimepicker();
if($timepicker1.val() && $timepicker2.val())
 //call awesome calculation function

You should use the button-tag instead of the submit-button:

<input type = button ...> or <button ....>

Now you are able to use the onClick-Event

<input type = 'button' onclick='onClickEvent()'>


function onClickEvent()
function sendData(method,data,dataType,adress, funcSuccess, funcError)
    type: method,
    url: adress,
    data: data,
    success: function(jqXHR, textStatus, errorThrown)
    error: function (jqXHR, textStatus, errorThrown)
    dataType: dataType,