Forum Discussion
JavaScript help
Can someone help me with coding javascript to display a current date in the following example format: Monday, July 8, 2025.
Appreciate any help and many thanks!
I don’t think holding the current date value in a text entry field is a good idea, as it can be easily overridden by the learner’s input. Instead, you can display the current date in a text box by referencing the current_date variable.
The JavaScript code for setting the current date is included in the attached .story file.
- NedimCommunity Member
I don’t think holding the current date value in a text entry field is a good idea, as it can be easily overridden by the learner’s input. Instead, you can display the current date in a text box by referencing the current_date variable.
The JavaScript code for setting the current date is included in the attached .story file.
- NikkiLowin-3dc2Community Member
Wow. I have been using text entry fields across several tutorials. Okay. Now I know better. Thank you for the JavaScript. I over complicate things. You have been a tremendous help. I can't thank you enough, Nedim!
- NedimCommunity Member
No problem. You are welcome, Nikki.
- LucyLouCommunity Member
Hi, I am also looking for this. I have got my javascript to work however showing as mm/dd/yyyy however want it to show as dd month(long) yyyy (10th March 2025)
I tried to open your file that you attached however it doesn't allow me to open it 😑
Please could you copy and paste the javascript used at all?- NedimCommunity Member
Execute JavaScript when the timeline starts:
var options = { year: 'numeric', month: 'long', day: 'numeric' }; var currentDate = new Date().toLocaleDateString('en-GB', options); setVar('currentDate', currentDate);
Ensure there is a custom text variable "currentDate" in your project.
- LucyLouCommunity Member
That hasn't worked for me 😔 However I managed to work it out - thank you 😆