1
I am making a system and tried to use javascript to ensure that the user does not give the SUBMIT with the final date before the initial date. Almost everything worked out, but in DATE_END input it is no longer possible to enter a date or time, just using the up and down arrows.
The complete source code is:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>End After Start</title>
<script type="text/javascript">
function datestart(value){
document.getElementById("date_end").value = value;
}
function dateend(value){
var vdatestart = document.getElementById("date_start").value;
if (value<vdatestart){
document.getElementById("date_end").value = vdatestart;
}
}
</script>
<style>
.col-30 {
float: left;
width: 30%;
margin-top: 6px;
}
.col-70 {
float: left;
width: 70%;
margin-top: 6px;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.row:after {
display: table;
clear: both;
}
</style>
</head>
<body>
<?php
$datemin = '2018-05-01T00:00';
$datemax = '2018-05-22T08:00';
$currentdate = '2018-05-22T08:00';
?>
<div class="container">
<form name="form1" action="datetime1.php" method = "post">
<div class="row">
<div class="col-30">
<label>Start Date and Time from Start:</label>
</div>
<div class="col-70">
<input type='datetime-local' name='date_start' id='date_start' min='<?php echo $datemin; ?>' max='<?php echo $datemax; ?>' required value='<?php echo $currentdate; ?>' onchange="datestart(this.value);" onclick="datestart(this.value);" />
</div>
</div>
<div class="row">
<div class="col-30">
<label>End Date and Time:</label>
</div>
<div class="col-70">
<input type='datetime-local' name='date_end' id='date_end' min='<?php echo $datemin; ?>' max='<?php echo $datemax; ?>' required value='<?php echo $currentdate; ?>' onchange="dateend(this.value);" onclick="dateend(this.value);" />
</div>
</div>
<div class="row">
<input type="submit" name="submit" value="Send">
</div>
</form>
</div>
</body>
</html>
I tried to put it on an online server, but I couldn’t because of PHP which is the main language of the system. Would anyone have any solution other than after SUBMIT?
Only I need to show the date and time and have minimum and maximum besides showing the calendar. This in HTML is ready.
– Wellington Telles Cunha
Dude, that’s another problem. You’ll need to use a jquery ui, or any other lib for user interface. This link will help you: https://jqueryui.com/datepicker/
– Micael Pereira
The company has taken fear of java/javascprit among others... as HTML5 already has the calendar.... this is right... the problem javascript at some point blocks from typing the date and time at the final date of the task
– Wellington Telles Cunha