The purpose of this function is to load a timestamp by default into a form element, but it appears this javascript function is never loaded when the HTML renders.
<!DOCTYPE html>
<html>
<script type=”text/javascript”>
function Timestamp() {
const currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var dash = "-";
var space = " ";
var colon = ":";
var hour = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var timestamp = year.concat(dash, month, dash, day, space, hour, colon, minutes, colon, seconds);
document.getElementById("curr").innerHTML = timestamp;
console.log(timestamp);
}
</script>
<head>
<title>Create New Reservation</title>
</head>
<body onload="Timestamp()">
<h1>Enter Reservation Details</h1>
<h3>Current Time: <span id="curr"></span></h3>
<form method="post" action="form.php">
<fieldset>
<label>Current Time</label>
<type="text" />
<input type="text" id="occurred" name="occurred">
</form>
</body>
</html>
The console outputs the following error:
"Uncaught ReferenceError: Timestamp is not defined"
”text/javascript” will not work. use "text/javascript"
<!DOCTYPE html>
<html>
<head>
<title>Create New Reservation</title>
</head>
<body onload="Timestamp()">
<h1>Enter Reservation Details</h1>
<h3>Current Time: <span id="curr"></span></h3>
<form method="post" action="form.php">
<label>Current Time</label>
<type="text" />
<input type="text" id="occurred" name="occurred">
</form>
<script>
function Timestamp() {
const currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var dash = "-";
var space = " ";
var colon = ":";
var hour = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var timestamp = year + dash + month + dash+ day+ space+ hour+ colon+ minutes+ colon+ seconds;
document.getElementById("curr").innerHTML = timestamp;
console.log(timestamp);
}
</script>
</body>
</html>