2013-04-24 59 views
0

將價值返回£0.00我有一個下拉菜單用於選擇價格選項。默認選項是選擇,然後選擇一個選項後,我會更新總價格以反映選項價格。使作品不錯,但如果你回去選擇「選擇」,我再次得到我的總價值「未定義」 ......如果選擇菜單返回到選擇

下面的代碼

標記

<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); 
     }); 


    }); 
+0

您確定它是在products.prices中定義的嗎? – MasNotsram 2013-04-24 11:07:42

回答

0

也許你應該首先將默認價格添加到products.prices數組?

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