Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2013, 07:44 PM   PM User | #1
DDH
New to the CF scene

 
Join Date: Jan 2013
Posts: 9
Thanks: 10
Thanked 0 Times in 0 Posts
DDH is an unknown quantity at this point
Javascript stack

Hi,

I am having troubles creating java script stack. Basically I need to store user input from text box into stack and display how the stack grows in text box at the time of storing the values, if that makes sense. Can anyone give me a hand. This is what I got so far, but instead of stacking elements one over another it adds em one below another:

Code:
function userInput(e){
 
 var x = document.getElementById("TextBox1");
 
 if(e.which == 13)
 
 if (document.getElementById("input").value > "") {
 
 backStack.push(document.getElementById("input").value);
 
 x.innerHTML = backStack.join('<br/>'); 
 
 document.getElementById("input").value = "";
 
    }
 }
DDH is offline   Reply With Quote
Old 01-20-2013, 08:44 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
If you want the most recently added entry at the top instead of at the bottom then replace push() with unshift()
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
DDH (01-20-2013)
Old 01-20-2013, 08:49 PM   PM User | #3
DDH
New to the CF scene

 
Join Date: Jan 2013
Posts: 9
Thanks: 10
Thanked 0 Times in 0 Posts
DDH is an unknown quantity at this point
Thanks! That worked, but I need to do it with LIFO so I think I must use push() and pop() instead of shift() and unshift() . Thank you again for the repsonse
DDH is offline   Reply With Quote
Old 01-20-2013, 09:09 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
LIFO can use either push() and pop() or unshift() and shift() - which you use only affects which end of the array is which

FIFO can use either push() and shift() or unshift() and pop()
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
DDH (01-20-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:35 AM.


Advertisement
Log in to turn off these ads.