0

I am trying to enter the current date when the page loads. I am able to store it to a variable, I am just having trouble entering that variable onto the page.

HTML:

<span id='test'>x</span>

Javascript:

window.onload = function() {
  var month = new Array("January", "February", "March", "April", "May", "June", "July",    "August", "September", "October", "November", "December");
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth();
  var currentMonth = month[mm];
  var yyyy = today.getFullYear();
  today = currentMonth + ' ' + dd + ', ' + yyyy;
  document.getElementById('test').innertext() = today;
}

JSFIDDLE

2
  • 1
    .innerText = "some text" innerText, innerHTML are not functions, even if they were you do not assign values to the return of a function Commented Mar 6, 2014 at 20:00
  • I second what Patrick said. Commented Mar 6, 2014 at 20:01

3 Answers 3

3

Change this:

document.getElementById('test').innertext() = today;

for this:

document.getElementById('test').innerHTML = today;
Sign up to request clarification or add additional context in comments.

Comments

0

Use this code, it works

window.onload = function() {
      var month = new Array("January", "February", "March", "April", "May", "June", "July",    "August", "September", "October", "November", "December");
      var today = new Date();
      var dd = today.getDate();
      var mm = today.getMonth();
      var currentMonth = month[mm];
      var yyyy = today.getFullYear();
      today = currentMonth + ' ' + dd + ', ' + yyyy;
      document.getElementById('test').innerHTML = today;
    }

Comments

0

You have a problem at the following line of code because you treat the innerText property as if it was a function and you don't camel-case it (JavaScript is a case-sensitive language):

 document.getElementById('test').innertext() = today;

So change it to:

document.getElementById('test').innerText = today;

Here is the working example: http://jsfiddle.net/ynevet/cNCf4/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.