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-14-2013, 12:51 AM   PM User | #1
redshine6
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
redshine6 is an unknown quantity at this point
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>
redshine6 is offline   Reply With Quote
Old 01-14-2013, 12:59 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,376
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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;
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
array, javascript, pull, push

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 03:29 AM.


Advertisement
Log in to turn off these ads.