Answer the question
In order to leave comments, you need to log in
Difference between dates on onchange?
The task is, when specifying two dates, to calculate the difference between them and send it via Ajax to PHP.
Two inputs with drop-down calendars:
Дата заезда<br/>
<input id="date1" class="date-pick" name="address" type="text" value=""><br/>
Дата выезда<br/>
<input id="date2" class="date-pick" name="date2" type="text" onchange="update_cost('{$prod_id}',my_new"><br/>
<script language="javascript"><br/>
var my_new;<br/>
my_new = my_day();<br/>
function my_day() {<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/>
Answer the question
In order to leave comments, you need to log in
Surely drop-down calendars have their own method for getting the selected date value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question