<input id="date" type="text" value="10-12-202" />
<select id="terms" onchange="return dueDate()">
<option value=""></option>
<option value="10">10</option>
<option value="20">20</option>
<option value="20">20</option>
<option value="90">90</option>
</select>
<input id="due_date" readonly="" type="text" />
<script>
function dueDate(){
var terms=parseFloat (document.getElementById("terms").value);
var inv_date=document.getElementById("date").value;
var res = inv_date.split("-");
inv_date = res[2]+"-"+res[1]+"-"+res[0];
var today =new Date(inv_date);
var dueDate =new Date(inv_date).setDate(today.getDate()+terms);
var newDate = new Date(dueDate);
//alert(newDate);
//newDate = newDate.toLocaleString();
var date = newDate.getDate();
date = (date <= 9) ? '0'+date : date;
var month = newDate.getMonth()+1;
month = (month <= 9) ? '0'+month : month;
var year = newDate.getFullYear();
//alert(month);
document.getElementById("due_date").value=date+"-"+month+"-"+year;
}
</script>
No comments:
Post a Comment