1

I'm sure this is the simplest bit of code you'll see all day; I feel silly asking for help on this, but I've been staring at it for an hour and am going crazy because I can't figure out WHY it won't work.

index.html

<html>
<head>
<SCRIPT type="text/javascript" src="include.js"></SCRIPT>
</head>
<body onload="test()">
<p id="center"></p>
</body>
</html>

include.js

function test()
{
  document.getElementByID('center').innerHTML="testing";
}

When I open index in a browser window, it just gives me a blank page. I tried putting an alert window in the first line of the test() function, and it alerted, so it's getting that far. If I put the alert after the "testing" line, it doesn't happen.

Thanks in advance.

1
  • Id shouldn't be capitalized. "getElementById" Commented Jan 22, 2013 at 19:42

3 Answers 3

3

Replace

getElementByID

with

getElementById

But you should look at the console to find those errors. You can't go very far without such a tool.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I knew I'd kick myself.
I hope you learn how to avoid those bugs in the future. Please really read the link I gave.
0

should be getElementById - not ID at the end!

Try hitting f12 in your browser. You should get an error console to help with these simple issues.

Comments

0

Try:

window.onload=function test()
{
  document.getElementById('center').innerHTML="testing";
}

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.