get current date value to populate an input field
-
Using contact form 7 on my website, would like to retrieve the form submission date as an input value to use in “Jetpack CRM” for a custom field. I want to avoid that the user has to select the date with a date picker.
Until now i only managed to get the current date value with[hidden today_date _date]
that i can use in email templates, but this is not the thing i need.
What i tried so far (after reading How do I change the value of text field in wordpress contact form 7 using javascript):
In contact form 7, i added the field<label> [text submission_date id:submissiondate ""] </label>
, hoping that the javascript would fill out the empty quotes with the dateTime value.
With the plugin “WP Headers and Footers” i added the scriptvar today = new Date(); var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate(); var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var dateTime = date+' '+time; document.getElementById("submissiondate").value = dateTime;
I tried the script in the header, in the body and in the footer.
The result is always: an empty form field and a js error:Uncaught TypeError: document.getElementById(…) is null
Can anybody help me with this?
- The topic ‘get current date value to populate an input field’ is closed to new replies.