Thursday, February 2, 2017

Date - Date in Javascript





HTML
<form method="post"  name="fillup">

<input type="text"  placeholder="yyyy/mm/dd" name="filing_deadline" onchange="getStatus()">
<input type="text" placeholder="yyyy/mm/dd"  name="actual_date_of_filling" onchange="getStatus()" >
<input type="text" readonly name="filing_status" onchange="getStatus()">

</form>

JAVASCRIPT

<script type="text/javascript" >
function getStatus() {
var actual = new Date(document.fillup.actual_date_of_filling.value);
var deadline = new Date(document.fillup.filing_deadline.value);
var timeDiff = deadline.getTime() - actual.getTime();
var DaysDiff = timeDiff / (1000 * 3600 * 24);
var stat="";
if(DaysDiff==0){
stat="Within the deadline";
}else if(DaysDiff>0){
if(DaysDiff>1) stat=DaysDiff+" Days Advance";
else stat=DaysDiff+" Day Advance";
}else if(DaysDiff<0){
   if(Math.abs(DaysDiff)>1) stat=Math.abs(DaysDiff)+" Days Late";
else stat=Math.abs(DaysDiff)+" Day Late";
}else{
stat="";
}
 document.fillup.filing_status.value=stat;
}
<script>

No comments:

Post a Comment