Pushing, Popping, and Displaying the Contents of a Stack : Stack « Language Basics « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Language Basics » Stack 
Pushing, Popping, and Displaying the Contents of a Stack

<HTML>
<HEAD>
<TITLE>Stacking up!</TITLE>
<SCRIPT
var stack = new Array()
function pushStack(newVal) { 
   stack.push(newVal)

function popStack() { 
   var popVal = stack.pop()
   if (popVal == undefined
      return "Empty stack!"
   else 
   return popVal; 

function showStack(theSelect){ 
   theSelect.options.length = 0
   for (var i = 0; i < stack.length; i++){ 
      var theOption = new Option(stack[i])
      theSelect.options[theSelect.options.length= theOption; 
   

</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT type=text name=txtPush>
<INPUT type=button value="Push" onClick='pushStack(txtPush.value); txtPush.value=""; showStack(theList);'>
<SELECT name="theList" size=12>
<OPTION>Displays the current state of the stack! 
</SELECT>
<INPUT type=text name=txtPop size=25>
<INPUT type=button value="Pop" onClick="txtPop.value = popStack(); 
   showStack(theList);">
</FORM>
</BODY>
</HTML>


           
       
Related examples in the same category
1. Simple Stack Example
ww__w___.___j___a___va_2___s__.com | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.