2016-08-03 7 views
-1

2つの合計を1つの合計にしたいと思っています...私はまだ多くのことを試みましたが、何もうまくいかなかったかもしれません。 10月2日が10月1日、2日に戻ってくると、私はティーカップの総価格が残っているにもかかわらず、値を0に戻すことはできません。jQuery - フォームの2つの値を合計

多分それを溶かすことができましたただ1つの見積もりで?

<script type="text/javascript"> 
 
    function einblenden(){ 
 
     var land = document.getElementById('tea-date').selectedIndex; 
 
     if(land == 1) { 
 
document.getElementById('tea').style.display = "block"; 
 
document.getElementById('tea-sum').style.display = "block"; 
 
document.getElementById('tea-input').value = ""; } 
 
      else { 
 
document.getElementById('tea').style.display = "none"; 
 
document.getElementById('tea-sum').style.display = "none"; 
 
document.getElementById('tea-input').value = ""; 
 
}  } 
 
</script> 
 

 
<script type="text/javascript">// <![CDATA[ 
 
jQuery(document).ready(function(){ 
 
jQuery("#tea-seat").bind("keyup change", function(e){ var val1 = jQuery("#tea-seat").val(); var val2 = 30; jQuery("#tea-sum").text(val1*val2); }); 
 
jQuery("#tea-input").bind("keyup change", function(e){ var val3 = jQuery("#tea-input").val(); var val4 = 17.50; jQuery("#tea-cup-sum").text(val3*val4); }); 
 
}); 
 
// ]]></script>
<p>Date*  
 
     <select name="tea-date" id="tea-date" onchange="einblenden();"> 
 
      <option value="1. Oct 2016">1. Oct 2016</option> 
 
      <option value="2. Oct 2016">2. Oct 2016</option> 
 
     </select> 
 

 
<p>Seats*<br /> 
 
[number* tea-seats min:1 max:50 default:1 id:tea-seat]</p> 
 

 
     <div id="tea" style="display: none;"> 
 
<p>reserve tea<br>(17.50 $/cup)<br /> 
 
[number cup-tea min:0 max:50 default:0 id:tea-input] Cup/s</p> 
 
     </div> 
 

 
<p><strong>Total Price of seats: <span id="tea-sum"></span> Money</strong></p> 
 
     
 
<p><strong>Total Price of Tea Cups: <span id="tea-cup-sum"></span> Money</strong></p> 
 

 
<p><strong>Total Price of everything: <span id="total-tea"></span> Money</strong></p> 
 

 
<p>[submit "submit text"]</p>

+4

あなたが入力したHTMLには、これらのIDを持つ入力要素も要素もありません。また、あなたは閉じた ''をコメントアウトしました。 –

+0

申し訳ありませんまだ準備ができていません...私の悪い...私は新しいです... –

+0

あなたのhtmlはまだ無効です。 –

答えて

0

私はあなたがすべてのものをやろうとしているものであってもわからないんだけど、ここではこれは小さな一例です:

$(document).ready((function() { 
    var setValue = function() { 
     var seats = parseFloat($("#tea-sum").val()); 
     var cups = parseFloat($("#tea-cup-sum").val()); 
     $("#total-tea").val(seats+cups); 
    } 
    $("#tea-sum").change(setValue); 
    $("#tea-cup-sum").change(setValue); 
})) 

https://jsfiddle.net/zp88wmfv/

欠けているもの:フィールドに文字または無効なフォーマット番号が含まれている可能性があります。おそらく、この方法で入力フィールドを必要としないでしょう。

関連する問題