如果选择菜单返回选择,则将值设置回£0.00

时间:2013-04-24 10:58:59

标签: php javascript

我有一个选择价格选项的下拉菜单。默认选项是选择,然后选择一个选项后,我会更新总价格值以反映期权价格。这样就可以了,但是如果你再次选择'选择',我的总价值会得到'未定义'......

这是代码

标记

<form class="optionsForm" name="form{$option.optionID}" action="/view-cart.html" enctype="multipart/form-data" method="post" >

            <input type="hidden" value="{$option.optionPrice}" name="productPrice" id="optionPrice" />
            <input type="hidden" value="{$product.productID}" name="instanceID" />
            <input type="hidden" value="add" name="action"/>
            <input type="hidden" value="products" name="componentID"/>
            <input type="hidden" value="{$option.optionID}" name="options[optionID]" id="optionID"/>
            <input type="hidden" value="add" name="action"/>

            {* If there is only one option, don't show the select option row *}

            {if count($product.productOptions) > 1}

            <h4 class="optionsFormTitle">Please select your options</h4>

            <div class="optionsRow">

                <select name="options" class="dropDown">

                    <option value="0.00">Select</option>

                    {foreach $product.productOptions option}
                        <option value="{$option.optionID}">{$option.optionTitle}
                        {if $option.optionPrice > $product.pricesFrom} &pound;{$option.optionPrice}{/if}
                        </option>
                    {/foreach}           

                </select>

            </div>

            {/if}        


        <div {if count($product.productOptions) > 1} class="totalRow" {else} class="noOptionTotalRow" {/if} >        
            Total<span class="productPrice optionPrice"> &pound;0.00</span>

            <input type="submit" value="Add To Basket" class="buyNowButton" />
        </div>

    </form>

...的Javascript

        products.prices = new Array;

    $.get('/ajax/' + window.location.pathname, function(data) {

        for (var optionID in data)
            products.prices[optionID] = data[optionID];

        $('.optionsRow select').change(function() {
            var requested = $(this).val();
            $('.optionPrice').html('£' + products.prices[requested]);
            $('#optionPrice').val(products.prices[requested]);
            $('#optionID').val(requested);
        });


    });

1 个答案:

答案 0 :(得分:0)

也许您应该首先将默认价格添加到products.prices数组?

products.prices = new Array;
products.prices["0.00"] = "0.00";