Back
I would like to add the current date to a hidden HTML tag so that it can be sent to the server:
<input type="hidden" id="DATE" name="DATE" value="WOULD_LIKE_TO_ADD_DATE_HERE">
How can I add a formatted date to the VALUE attribute?
You can try using the code given below:
var today = new Date();var dd = today.getDate();var mm = today.getMonth() + 1; //January is 0!var yyyy = today.getFullYear();if (dd < 10) { dd = '0' + dd;} if (mm < 10) { mm = '0' + mm;} var today = dd + '/' + mm + '/' + yyyy;document.getElementById('DATE').value = today;
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
var today = dd + '/' + mm + '/' + yyyy;
document.getElementById('DATE').value = today;
31k questions
32.8k answers
501 comments
693 users