Community Forums 

Main Content

Help with multiple selection *and* running total

    Feb 21 2011 07:36:15


    Evolving Door

    Join date : 2011-01-29      Posts : 21

    I'm trying to streamline my order form. I need to have both multiple selection items (using radio buttons or dropdown lists) as well as single selection items that use checkboxes. I want to have a running total of the items selected, but I can't seem to do both the multiple selection AND the subtotal. I'm not a Javascript expert but I do know a bit (just enough to get myself into trouble <g>) and I do have a programming background. I've been trying to combine script features from various examples on -- a wonderful resource! -- but somehow I can't seem to get the two features to work together. Here's a sample script attempt that does pass the items through to the cart, but won't subtotal the multiple selection item on the original page:

    <!-- PRODUCT 2 -->
    <input type="hidden" name="product2" value="Product 2">
    <input type="checkbox" id="qty2" name="qty2" value="1" onClick="UpdateCost()">Product 2
    <input type="hidden" id="price2" name="price2" value="19.95">

    <!-- PRODUCT 3 -->
    <input type="checkbox" id="qty3" name="qty3" value="1"> Product 3
    <select name="productpr3">
    <option selected value="">Select Time Length</option>
    <option value="3 months:24.95">3 Months - $24.95</option>
    <option value="6 months:29.95">6 Months - $29.95</option>

    Select start date:
    <select name="product3[]">
    <option value=" starting today">Month</option>
    <option value=" starting Jan">Jan</option>
    <option value="starting Dec">Dec</option>

    <select name="product3[]">
    <option value="">Day</option>
    <option value=" 1">1</option>
    <option value=" 31">31</option>

    Your Total Is:
    <input type="text" id="totalcost" value="">&nbsp;
    <input type="submit" value="Buy Now">


    The UpdateCost function used to subtotal is from the sample site mentioned above:

    function UpdateCost() {
    var sum = 0;
    var qty,prc;
    for (i=1; i<10; i++)
    qty = 'qty'+i;
    prc = 'price'+i;
    if (document.getElementById(qty).checked == true)
    sum += Number(document.getElementById(prc).value);
    document.getElementById('totalcost').value = sum.toFixed(2);


    For the dropdown selection above, I've tried putting onChange="UpdateCost()" in the Select tag or in the Option tag, but this doesn't update the total at the bottom. Since the price varies with each selection, I can't connect the price or subtotaling to the qty checkbox; it has to be connected to the dropdown (or radio button input).

    The regular checkbox item subtotals fine though.

    Can anyone help me with the Javascript for this please? I've been trying to get this to work for over a week now and I'm almost ready to throw my computer out the window. Let me know if you need any other code that I'm using. I've tried to minimize the amount of code while providing enough information.

    Many thanks in advance!

    Feb 21 2011 14:38:07


    Debbie Q

    Join date : 2008-09-18      Posts : 4998

    Not knowing anything about Javascripting I always opt for the least resistance method and not try to recreate the wheel. There is a very nice easy to use price option script available for sale here.

    Debbie Q

    Mal's Support:
    GT's Forms and examples:
    Helpful java scripts:
    Shipping help documents:

    My Create-A-Book Publishing -
    Personalized Books, Music CDs and Gifts for all ages and occasions.

    Please help me out and share my site on your networks.

    Feb 21 2011 18:00:15


    Evolving Door

    Join date : 2011-01-29      Posts : 21

    Hi Debbie,

    Thanks for your reply. I suspect my needs might be a little different from what they're offering. It would be wonderful to find someone who had already invented this particular "wheel" ;-) but I don't think theirs is quite what I'm looking for. I'm building an order page that will let the user select one or more of a number of items, some of which have various options to choose from. It looks like their Dynamic List script is intended for one product purchase, even though it allows you to select from a number of options. I was kind of hoping to find something that I wouldn't have to buy, too. That's why I'm trying to do this myself, but need some help with it. Thanks for the suggestion, though. :-)