Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,102
    Thanks
    23
    Thanked 594 Times in 593 Posts
    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;


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •