I use the onload function to show the date when the page is opened, and it’ working correctly.
But when I added the username to this function, it doesn’t display anything (I want the username to be displayed at the top of the page too.)
This is the function I’m using:
window.onload = function () {
var newDate = new Date();
$('#dateday').val(newDate.getFullYear() + '-' + newDate.getMonth() + '-' + newDate.getDate()); // This is showed correctly
alert(localStorage["username"]); // It's alerted correctly
$('#usernamethename').val(localStorage["username"]); //This is not displayed.
The html code:
<h3 id="usernamethename"></h3>
<input id="dateday" type= text></input>
Do you know why isn’t the username displayed ? & if there are any better ideas to show the name at the top the page, I’d really appreciate it if you mentioned them.
Thanks a lot 🙂
Try this: