I know if you use a Date field you can tell it to default the current date in the field. Is there a way to use a token to do the same thing in a Custom HTML field?
Question
Question
Answer
$(document).ready(function() { var d = new Date().toUTCString(); $('#q1 textarea').val(d); });
I think the issue was that you weren't adding the parenthesis after your .toUTCString method call.
Edit: If it's a Custom HTML field, the code will be a little different. Let's assume your custom HTML field contains a textarea with date as its ID.
$(document).ready(function() { var d = new Date().toUTCString(); $('#date').val(d); });
Replies
you can use javascript to pull in the date from the browser and load it into that field. Shouldn't be too difficult, take a look at the link below as a good starting point:
I am trying to add a date to the custom HTML field by using the following code:
var d = new Date(); document.getElementById("date").innerHTML = d.toUTCString;
The date does not show up on the form though, instead it displays it as follows:
Any ideas why it will not display correctly? If I just use:
document.getElementById("demo").innerHTML = Date();
then it displays correctly, but I would like to format it differently.
try storing d.toUTCString to a new variable and then setting the innerHTML to that variable. Javascript is only inserting the function name instead of running it currently, by doing as I am saying, you should have the proper output you are looking for
Have you tried .text() instead of .innerHTML()?
when I ad .text rather than .innerHTML, nothing shows for the date.
$(document).ready(function() { var d = new Date().toUTCString(); $('#q1 textarea').val(d); });
I think the issue was that you weren't adding the parenthesis after your .toUTCString method call.
Edit: If it's a Custom HTML field, the code will be a little different. Let's assume your custom HTML field contains a textarea with date as its ID.
$(document).ready(function() { var d = new Date().toUTCString(); $('#date').val(d); });
I have a custom HTML field with a <span id=date></span> in it. How do I use what you posted to place the date within the span tag? It was working with the original code I posted.
Thank you for your help. I was able to figure out my previous question. Below is the final code I used:
var d = new Date().toDateString(); $('#date').after(d);
You're welcome!