1

I'm working on an application that will have an input field as DATE.
Which changes daily, Based on the date the data will be displayed.

I got the solution to my problem in HTML5 Input Type Date -- Default Value to Today? this discussion .

But when i tried to code in intel XDK .its not displaying todays date . Here is the code.

var date = new Date();

var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();

if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;

var today = year + "-" + month + "-" + day;       
document.getElementById("theDate").value = today;
<input type="date" id="theDate">

I have tried same code in my project . But it gives result likeenter image description here

Thanks in advance.....

Community
  • 1
  • 1
Mr.Robot
  • 489
  • 2
  • 8
  • 17
  • its look like the code just dosent run.. do you have errors in the console? – Amir Bar Jul 15 '15 at 16:17
  • It seems to work fine for me. Try double checking the value of `today` just before the element value is changed. It looks like if the string is not in the form that it understands as a date, you'll see ymd as above. In my case it converted it to `dd/mm/yyyy`, but it understood 2015-07-15, which is what was assigned to it. – OldGeeksGuide Jul 15 '15 at 21:49
  • @OldGeeksGuide i tried it but id didnt worked. :( – Mr.Robot Jul 21 '15 at 15:25
  • Do you mean the value in `today` was incorrect or that it had the right value but it didn't come out on the page in your app? – OldGeeksGuide Jul 24 '15 at 20:41
  • @OldGeeksGuide the value was correct, but it didn't show up on the page.. Why so – Mr.Robot Aug 01 '15 at 10:14
  • Can you try setting the value to some constant and then see why it doesn't show up? You'll need to use the CDT debugger to examine why it's not showing up. – OldGeeksGuide Aug 06 '15 at 23:27

1 Answers1

0

Moment.js is very helpful Moment.js helped me. Thanks for your replies .. :)

  1. First import Moment.js file into your code.
  2. document.getElementById('today').value = moment().format('YYYY-MM-DD');
  3. Use the above piece of code in the separate function where the page gets automatically loaded.

Thanks for replies.

Mr.Robot
  • 489
  • 2
  • 8
  • 17