CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   Display Results for Push & Pop Values (http://www.codingforums.com/showthread.php?t=285737)

redshine6 01-14-2013 12:51 AM

Display Results for Push & Pop Values
 
I have checked the forum and there are similar threads, but nothing that deals exactly with my issue.
I have 2 Arrays and a variable. I need to push an item onto the variable, and then with a second click push it onto Array 1. Then with i click a second button, the item in the varible is push onto Array 2, and the item in Array 1 is Poped onto the Variable.

Here is the code i have come up with, but i cannot pop the item from the Variable onto Array 2.

Any ideas:

<HTML>
<HEAD>
<TITLE>Stacking up!</TITLE>
<SCRIPT>



// 'txtPop.value = popBackStack();showStack(theList);pushForStack(txtPop.value);

// 'PushForStack(txtPop.value);txtPush.value"";txtPop.value = popBackStack();showStack(theList);showStack2(theList2);'


var backStack = new Array();
var forStack = new Array();
var curUrl = document.getElementById("txtPop");

function pushStack(newVal) {
backStack.push(curUrl);
curUrl = newVal;
}

function pushForStack(newVal) {
CurUrl = newVal;
forstack.push(curUrl);
}

function popBackStack() {
var popVal = backStack.pop();
if (popVal == undefined)
return "Nothing left!";
else
return popVal
}

function popForStack() {
var popVal = forStack.pop();
if (popVal == undefined)
return "Enter a new URL";
else
return popVal;
}

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

function showStack2(theSelect){
theSelect.options.length = 0;
for (var i = 0; i < forStack.length; i++){
var theOption = new Option(forStack[i]);
theSelect.options[theSelect.options.length] = theOption;
}
}
</SCRIPT>



</HEAD>
<BODY>
<FORM>
<table width="104%" height="364" border="5" cellpadding="3" cellspacing="3">
<tr>
<th width="30%" height="78" scope="col"><p>
<INPUT type=button value="Back" onClick='txtPop.value = popBackStack();showStack(theList);pushForStack(curUrl);
showStack2(theList2);'></p></th>
<th width="46%" scope="col"><p>
<center>
<INPUT type=text name=txtPush>
<INPUT type=button value="Push" onClick='pushStack(txtPush.value);txtPush.value="";txtPop.value = curUrl; showStack(theList);'>
</center>
</p></th>
<th width="24%" scope="col"><p><INPUT type=button value="Forward" onClick="txtPop.value = popBackStack();showStack2(theList2);"></p></th>
</tr>
<tr>
<td><p><center>
<SELECT name="theList" size=12>
</SELECT>
</center></p></td>
<td><p><center><INPUT type=textki name=txtPop size=25></center></p></td>
<td><center>
<SELECT name="theList2" size=12>
</SELECT>
</center></td>
</tr>
</table>
</FORM>
<p>&nbsp;</p>
</BODY>
</HTML>

sunfighter 01-14-2013 12:59 PM

To put your code into the code tags use the # icon not the #i icon.
This should be in the javascript form not the dom and json form.
You don't identify array 1 or array 2 so I have to guess, but I think your problem is this function:
Code:

function pushForStack(newVal) {
CurUrl = newVal;
forstack.push(curUrl);
}

CurUrl = newVal; The capital makes this a different variable. Think it S/B curUrl = newVal;


All times are GMT +1. The time now is 02:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.