Reputation: 737
I have created a javascript code that lets the user input something then it should display after the input but my display seems to not work at all, I am using document.getElementById to display the array content per input but it is not working.
Here is my complete code:
<html>
<meta charset="UTF-8">
<head>
<title>Sample Array</title>
<script>var index = 0;</script>
</head>
<body>
<p id = "display">
Input:
<input type="text" id="input">
<input type="button" value="GO" onClick="press(input.value)">
<script>
var sample = new Array();
function press(Number)
{
sample[index] = Number;
document.getElementById("display").InnerHTML += sample[index] + " ";
index++;
}
</script>
</body>
</html>
What seems to be the problem? I am still learning the basics please bear with me.
Upvotes: 0
Views: 68
Reputation: 66
The problem is with "InnerHTML". The correct syntax is "innerHTML" with small "i".
Upvotes: 1
Reputation:
First your <p> is not complete; <p id = "display"></p>
Second its:
document.getElementById("display").innerHTML += sample[index] + " ";
Upvotes: 1
Reputation: 3260
I made two tiny changes that seem to make this work.
First, close the <p>
tag so that when you set innerHtml
it does not include the inputs.
Second, change InnerHHTML
to innerHTML
. Methods and properties are case sensitive.
<p id = "display"></p>
Input:
<input type="text" id="input">
<input type="button" value="GO" onClick="press(input.value)">
<script>
var sample = new Array();
function press(Number)
{
sample[index] = Number;
document.getElementById("display").innerHTML += sample[index] + " ";
index++;
}
</script>
Upvotes: 1
Reputation: 4391
change
document.getElementById("display").InnerHTML
to
document.getElementById("display").innerHTML
(note the lowercase i
Upvotes: 1