JSFiddle - React, Tailwind, and code Playground
by Joe
HTML
<input type="date" id="vochDate" class="form-control" onload="setCurrentDate()">
<div class="form-group col-4 vocSub" style="margin-bottom: 0px !important;">
<button type="reset" class="btn btn-default reset-btn stock_rst cshRst" id="reset-btn" value="Reset">Reset</button>
</div>
JavaScript
$(document).ready(function() {
// $("#vochDate").date();
$("#vochDate").change(function() {
var selDate = $(this).val();
if (isFutureDate(selDate))
$("#body").html("You have selected future date: " + selDate + "." + " Do you want to continue?");
else
$("#body").html("You have selected past date: " + selDate + "." + " Do you want to continue?");
modal.style.display = "block";
else if
$("#body").html("You have selected past date: " + selDate + "." + " Do you want to continue?");
modal.style.display = "block";
});
function isFutureDate(idate) {
idate = new Date(idate).getTime();
return (today - idate) < 0 ? true : false;
}
// Get the modal
var modal = document.getElementById("myModal");
// Get the <span> element that closes the modal
var mainSpn = document.getElementsByClassName("mainSpn")[0];
// Get the Cancel button element that closes the modal
var datCancel = document.getElementsByClassName("dateCan")[0];
// Get the ok button element that allows and closes the modal
var dateOk = document.getElementsByClassName("dateOk")[0];
// When the user clicks on <span> (x), close the modal
mainSpn.onclick = function() {
modal.style.display = "none";
$('#vouchDate').val(setCurrentDate());
}
datCancel.onclick = function() {
modal.style.display = "none";
// Date now = new Date();
setCurrentDate();
}
dateOk.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
});
function setCurrentDate() {
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
var today = year + "-" + month + "-" + day;
...