The difference between the dates when onchange?

The challenge is when you specify two dates, calculate the difference and send it via Ajax to PHP.


Two input with drop-down calendars:
Date of arrival<br>
<input id="date1" class="date-pick" name="address" type="text" value=""><br>
Date of departure<br>
<input id="date2" class="date-pick" name="date2" type="text" onchange="update_cost('{$prod_id}',my_new"><br>



Script:
<script language="javascript"><br>
var my_new;<br>
my_new = my_day();<br>
my_day function() {<br>
var date1 = document.getElementById('date1').value;<br>
var d1 = new Date(date1.replace(/(\d+).(\d+).(\d+)/, '$3/$2/$1'));<br>
<br / >
var date2 = document.getElementById('date2').value;<br>
var d2 = new Date(date2.replace(/(\d+).(\d+).(\d+)/, '$3/$2/$1'));<br>
var d = d2.getTime() - d1.getTime();<br>
return d/(1000*60*60*24);<br>
}<br>
</script><br>



But for some reason does not work, even with onchange="alert(my_new)" is issued to NaN, even if initially set the value for inputof with the dates, then everything works.
October 8th 19 at 00:38
1 answer
October 8th 19 at 00:40
Surely the drop-down calendars is your method for getting the selected date value.
Besides, with onchange="alert(my_new)" in my_new will be the initial value inputo. Better check this: onchange="alert(my_day())" - Sarah.Maggio99 commented on October 8th 19 at 00:43
Calendars are used jquery.datePicker
And your option really worked, seen really a problem since the first alert, to set the date gives NaN, and then have a normal result. - Erika.Ziemann45 commented on October 8th 19 at 00:46

Find more questions by tags AJAXJavaScript