You are viewing limited content. For full access, please sign in.

Question

Question

Can You Add Current Date to a Custom HTML Field?

asked on August 6, 2014

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?

0 0

Answer

SELECTED ANSWER
replied on August 7, 2014 Show version history
$(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);
});

 

0 0

Replies

replied on August 6, 2014

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:

 

http://www.w3schools.com/js/js_dates.asp

0 0
replied on August 7, 2014

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.

0 0
replied on August 7, 2014

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

0 0
replied on August 7, 2014

Have you tried .text() instead of .innerHTML()?

0 0
replied on August 7, 2014 Show version history

when I ad .text rather than .innerHTML, nothing shows for the date.

0 0
SELECTED ANSWER
replied on August 7, 2014 Show version history
$(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);
});

 

0 0
replied on August 7, 2014

I have a span tag with an id=date. How do I change what you posted so it puts the contents within the span?

replied on August 7, 2014

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.

0 0
replied on August 7, 2014

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);

 

1 0
replied on August 8, 2014

You're welcome!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.