You want to attach the current date to a hidden HTML field for server transmission:
<code class="html"><input type="hidden" id="DATE" name="DATE" value="WOULD_LIKE_TO_ADD_DATE_HERE"></code>
Solution:
Utilize the following JavaScript code:
<code class="js">const today = new Date(); const yyyy = today.getFullYear(); let mm = today.getMonth() + 1; // Months start at 0! let dd = today.getDate(); if (dd < 10) dd = '0' + dd; if (mm < 10) mm = '0' + mm; const formattedToday = dd + '/' + mm + '/' + yyyy; document.getElementById('DATE').value = formattedToday;</code>
Additional Information:
The above is the detailed content of How to Add a Formatted Date to an Input Field Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!