Grow your CSS skills. Land your dream job.

Changing Javascript Variable with Form

  • # October 29, 2009 at 11:54 am

    Hey Guys,

    I’ve been working on a little something :)

    I’ve been trying to use this shopping cart called simpleCart(js) its a javascript based shopping cart and I am stuck on just 1 thing. the shipping!

    Anyway the variable that controls the flatrate shipping for the cart is

    simpleCart.shippingFlatRate

    however I want the user to have a choice, to choose what shipping they want. so here is my code for the form.

    Code:

    I set it that when the user chooses an option it updates the variable and that is then passed into the flat shipping variable on the simpleCart(js) script however when I do this it always detect teh shipping as 0.00

    Please help me out! Any help will be greatly appreciated.

    Thank You

    # October 29, 2009 at 11:12 pm

    its ok guys I figured it out :)

    # January 21, 2010 at 3:20 pm

    so, how did you figured it out?
    I’m stuck in the same part…

    Any hint would be appreciated.

    # January 25, 2010 at 4:27 pm

    So the solution for me was really simple, you have to add at the end of the onchange script the Simplecart function: simpleCart.update();

    here is the script I made with lots of cut and paste from other places:

    Code:
    window.onload = initForm;
    function initForm(){
    document.getElementById(“shippingChoice”).selectedIndex = 0;
    document.getElementById(“shippingChoice”).onchange = populateApplication;
    }

    function populateApplication(){
    var edNum = document.getElementById(“shippingChoice”).selectedIndex;
    var edValue = document.getElementById(“shippingChoice”).options[edNum].value;
    simpleCart.shippingFlatRate = edValue;
    simpleCart.update();
    }

    And here is the HTML:

    Code:

    And the Paypal order worked fine…

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".