Reputation: 819
I wrote a todo in chrome that works fine. I tested it in IE8 and it didn't work. So I made a new file to write specifically in IE8, and I can't even get a simple function to work properly. I would like help in finding out what i'm doing wrong. Thank you to anyone that can school me on this.
HTML
<body>
<p>Home</p>
<form id="form1">
<input type="text" id="inItemText" />
</form>
<button id="btn1" onclick="doIt()">Press Here</button>
<p id="p1"></p>
</body>
Javascript
var inItemText = document.getElementById("inItemText");
function doIt() {
var itemText;
itemText = inItemText.value;
document.getElementById("p1").innerHTML = itemText;
form1.reset();
}
Upvotes: 0
Views: 860
Reputation: 780663
Make sure you do the inItemText
assignment after the DOM has been loaded. Otherwise, document.getElementById("inItemText")
won't find the element, because it doesn't exist yet.
Either put it at the end of the <body>
, or use window.onload
:
var inItemText;
window.onload = function() {
inItemText = document.getElementById("inItemText");
};
Upvotes: 1
Reputation: 1785
I think the issue is in this line:
itemText = inItemText.value;
You need to declare "inItemText" as a variable.
Perhaps replace it with:
itemText = document.getElementById("inItemText").value
Upvotes: 0
Reputation: 122
You're getting that error because inItemText
isn't defined. Use document.getElementById('inItemText')
.
Upvotes: 0