I am a total begginer at JavaScript and this question probably shows that.
I have this code:
<script>
function treatAsUTC(s) {
var b = s.split(/\D/);
return new Date(Date.UTC(b[2], b[1]-1, b[0]));
}
function daysBetween(startDate, endDate) {
startDate = treatAsUTC(startDate);
endDate = treatAsUTC(endDate);
return (endDate - startDate) / 8.64e7;
}
function calcDiff() {
document.querySelector('#tdays').value =
(daysBetween(document.querySelector('#startPicker').value,
document.querySelector('#endPicker').value));
}
</script>
<input type="text" id="sod" class="startd" value="10/02/2016" />d/m/y
<input type="text" id="dos" class="endd" value="12/02/2016" />d/m/y
<br>
<button onclick="calcDiff()">Calculate difference in days</button>
<input type="text" id="tdays" readonly>Days
Now I want the result to permanatly be displayed and updated as the dates change (they will be date pickers) rather than onClick.
I have tried innerHTML and document.write but I cant get it to work.
Any help will be greatly appreciated.
Thansk in advnace.
Ian
#tdays? You mean#result?