The user may choose a start date and end date for holiday. But, a problem may occur if the user choose an end date smaller than the start date.
Start Date :
<input type="date" class="form-control" name="startDate" id="from" required/>
End Date :
<input type="date" class="form-control" name="endDate" id="to" required/>
<br>
<input type ="hidden" name="empID" value="<%=empID%>">
<input type="hidden" name="activity" value="mobilityType"/>
<input type="hidden" name="status" value="pending"/>
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Submit">
<input class="btn btn-lg btn-danger btn-block" type="reset" value="Reset">
A code to alert the user, if the user select an end date smaller than start date should be like:
var from = $("#from").val();
var to = $("#to").val();
if(Date.parse(from) > Date.parse(to)){
alert("Invalid Date Range");
}else{
alert("Valid date Range");
}
Which should be the correct way to compare start date and end date?