View Single Post
Old 01-21-2013, 04:41 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
DDH (01-21-2013)