Actually, you don't even need the intermediate temporary variable (
temp in my code,
s in jmrker's code).
This works:
Code:
<!DOCTYPE html>
<html>
<body>
<body>
<form onsubmit="return false;">
<input type="text" value="" id="input" />
</form>
<br>Stack Display:<br>
<div id="TextBox1"></div>
<script type="text/javascript">
(
function()
{
var backStack = [ ];
var inp = document.getElementById("input");
inp.onkeyup = userInput;
function userInput(e)
{
if(e.which == 13 && inp.value != "" )
{
backStack.push( inp.value );
document.getElementById("TextBox1").innerHTML =
[].concat(backStack).reverse().join("<br/>");
inp.value = "";
inp.focus();
}
}
}
)();
</script>
</body>
</html>