1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Array in disarray

Discussion in 'JavaScript' started by gvm, Dec 14, 2006.

  1. #1
    My cart is working almost the way I want. myfunction below returns the last item in the cart. I want to join the items in the array. I'm using alert() as a flag for myself to see if my array is working. Thanks for any suggestions.

    function myfunction(){
    var mycart = new Array()
    JavaScript:top.MAIN.document.clientInfo.hideMessage.value = mycart
    for ( i=0; i<mycart.length; i++)
    alert(mycart)
    }


    function viewcart(){
    for (i in shoppingCart) {

    cartTotal = cartTotal + shoppingCart.price
    if (shoppingCart.itemNum != null)
    shoppingCart.display(true, top.MAIN.document)
    mycart = new Array(shoppingCart.description +"..."+ shoppingCart.price )
    }
    }
    <INPUT TYPE="button" onClick="JavaScript:top.HIDDEN.myFunction();" name="joe" value="Place Order">
     
    gvm, Dec 14, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    You mean you want to literally join the values of the array together into one string ?

    also alert(mycart) ....
     
    krakjoe, Dec 18, 2006 IP
  3. gvm

    gvm Guest

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, for every item the user clicks in adding to the cart I want to join together. The code works the way I want except for the second line in myFunction which returns a null value. I have changed the code from previous post to what you see now. I believe the null value is because the items passed to myFunction are not initialized, thus I receive the null error.
    I'm not sure how to initialize the array items in shopping cart passed to myFunction, or if I can even do that.

    for (i in shoppingCart) {
    cartTotal = cartTotal + shoppingCart.price
    if (shoppingCart.itemNum != null)
    shoppingCart.display(true, top.MAIN.document)
    myFunction(shoppingCart.description +"...$"+ shoppingCart.price + ".00")
    }
    function myFunction(theItems){
    alert(theItems)
    JavaScript:top.MAIN.document.clientInfo.message.value = theItems
    }
     
    gvm, Dec 18, 2006 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    perhaps if I could get a link to a live shopping cart that might help .....
     
    krakjoe, Dec 19, 2006 IP
  5. gvm

    gvm Guest

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok, thanks. I will post the link soon. I will have the cart working with a cookie returning the data, or an asp script. I prefer to have variables and arrays doing the processing in javascript. I'll get back with you on this.
     
    gvm, Dec 19, 2006 IP