幅1mmが100円、高さ1mmが100円だとして合計を自動で円の四角の中に出力したいです。
html
1<div class="cnt_form"> 2 <div class="area_size_form"> 3 <div class="wrap_input"> 4 <div class="wrap_input wrap_unit width"> 5 <?= $this->Form->number('width', ['required' => false, 'placeholder' => '幅', 'id' => "width", 'step' => 0.01]); ?> 6 <span>mm</span> 7 </div> 8 <div class="wrap_input wrap_unit hight"> 9 <?= $this->Form->number('height', ['required' => false, 'placeholder' => '高さ', 'id' => 'height', 'step' => 0.01]); ?> 10 <span>mm</span> 11 </div> 12 <div class="wrap_input wrap_unit total" data-ps="※概算"> 13 <input type="text" id="total" name="total" value="" placeholder=""> 14 <span>円</span> 15 </div> 16 </div> 17 </div> 18</div>
jquery
1<script> 2 $('#width').on('change', function () { 3 width = $(this).val(); 4 price_width = width * 100; 5 }); 6</script> 7 8<script> 9 $('#height').on('change', function () { 10 height = $(this).val(); 11 price_height = height * 100; 12 }); 13</script> 14 15<script> 16 $('#width, #height').on('change', function () { 17 total = price_width + price_height; 18 }); 19</script>
上記のコードで合計金額の取得まではできたのですが、
その合計を自動で出力する方法がわかりません。
もしくは、このコードよりも効率的な方法がございましたらご教示いただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。