How to set date type in JS

Asked

Viewed 31 times

0

I am trying to fill in an input date type, through a JS function I’m trying something like:

id('nascTit').value = 2005-05-15;

but the following error appears:

The specified value "yyyy-MM-dd" does not conform to the required format, "yyyy-MM-dd".

Does anyone know the right way to date?

Thanks in advance.

  • 3

    What is the return of the function id? Did you pass the date as a string? Why 2005-05-15 is a squid equal to 1985

  • what is id('') is a function?

  • 1

    missing quotation marks on the date. No?

  • it wasn’t quotes that were missing, this function actually used the Document.getElementById, I wasn’t understanding how it worked, but thanks guys..

1 answer

1


It worked for me that way:

document.getElementById("data").value = '2005-05-15';
<input type="date" id="data" name="data" />

  • 1

    thank you very much Virgil, worked here and helped me understand some things hehe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.