###前提・実現したいこと
いつもお世話になっております。
現在、チェックボックスにチェックを入れたら各商品の個数を変更できるようにし、その商品の金額と個数を乗算したもをテキストフィールドに表示をするという事をしております。
1商品毎の計算は現時点では問題なく動いているのですが、
以下の動きが実現できません。
・「商品合計(税込)」というテキストフィールドに5商品の加算したものを表示
・「送料」というテキストフィールドに5商品全てのセレクトボックスで選択された個数を乗算したものを表示
・「合計(税込)」というテキストフィールドに「商品合計(税込)」と「送料」を加算したものを表示
※「送料」は1個につき「315円」を加算したいです。
お手数おかけしますが、ご教授よろしくお願いします。
###該当のソースコード
javascript
1<script> 2$(function() { 3 4 //チェックボックスにチェックをいれないと選択不可 5 $('[name=item0], [name=item2], [name=item3], [name=item4], [name=item5]').prop('disabled', true); 6 7 //金額表示選択不可 8 $('[name=field0], [name=field2], [name=field3], [name=field4], [name=field5]').prop('disabled', true); 9 10 //合計金額 11 $('[name=field_total], [name=field_postage], [name=field_total2]').prop('disabled', true); 12 13 //item1 14 $('[name=itemlist1]').on('click', function() { 15 16 //チェックされていない場合は入力不可 17 if (!$('[name=itemlist1]').prop('checked')) { 18 $('[name=item0]').prop('disabled', true); 19 $(".item-wrap1").css('background-color', 'rgb(255, 255, 255)'); 20 } 21 //チェックされていたら入力可能 22 else if ($('[name=itemlist1]').prop('checked')) { 23 $('[name=item0]').prop('disabled', false); 24 $(".item-wrap1").css('background-color', 'rgb(250, 250, 242)'); 25 } 26 }); 27 28 //item2 29 $('[name=itemlist2]').on('click', function() { 30 //チェックされていない場合は入力不可 31 if (!$('[name=itemlist2]').prop('checked')) { 32 $('[name=item2]').prop('disabled', true); 33 $(".item-wrap2").css('background-color', 'rgb(255, 255, 255)'); 34 } 35 //チェックされていたら入力可能 36 else if ($('[name=itemlist2]').prop('checked')) { 37 $('[name=item2]').prop('disabled', false); 38 $(".item-wrap2").css('background-color', 'rgb(250, 250, 242)'); 39 } 40 }); 41 42 //item3 43 $('[name=itemlist3]').on('click', function() { 44 //チェックされていない場合は入力不可 45 if (!$('[name=itemlist3]').prop('checked')) { 46 $('[name=item3]').prop('disabled', true); 47 $(".item-wrap3").css('background-color', 'rgb(255, 255, 255)'); 48 } 49 //チェックされていたら入力可能 50 else if ($('[name=itemlist3]').prop('checked')) { 51 $('[name=item3]').prop('disabled', false); 52 $(".item-wrap3").css('background-color', 'rgb(250, 250, 242)'); 53 } 54 }); 55 56 //item4 57 $('[name=itemlist4]').on('click', function() { 58 //チェックされていない場合は入力不可 59 if (!$('[name=itemlist4]').prop('checked')) { 60 $('[name=item4]').prop('disabled', true); 61 $(".item-wrap4").css('background-color', 'rgb(255, 255, 255)'); 62 } 63 //チェックされていたら入力可能 64 else if ($('[name=itemlist4]').prop('checked')) { 65 $('[name=item4]').prop('disabled', false); 66 $(".item-wrap4").css('background-color', 'rgb(250, 250, 242)'); 67 } 68 }); 69 70 //item5 71 $('[name=itemlist5]').on('click', function() { 72 //チェックされていない場合は入力不可 73 if (!$('[name=itemlist5]').prop('checked')) { 74 $('[name=item5]').prop('disabled', true); 75 $(".item-wrap5").css('background-color', 'rgb(255, 255, 255)'); 76 } 77 //チェックされていたら入力可能 78 else if ($('[name=itemlist5]').prop('checked')) { 79 $('[name=item5]').prop('disabled', false); 80 $(".item-wrap5").css('background-color', 'rgb(250, 250, 242)'); 81 } 82 }); 83 84 85 $('[name=itemlist1]').click(function() { 86 if ($(this).is(':checked')) { 87 88 $('[name="item0"]').on('change', function() { 89 var itemPrice1 = 5076; 90 var itemPriceCount1 = $('[name="item0"] option:selected').text(); 91 $('[name="field0"]').val((parseInt(itemPrice1) * itemPriceCount1).toLocaleString()); 92 }); 93 94 } else { 95 $('[name="item0"] option').prop("selected", false); 96 $('[name="field0"]').val(0); 97 } 98 99 }); 100 101 102 $('[name=itemlist2]').click(function() { 103 if ($(this).is(':checked')) { 104 105 $('[name="item2"]').on('change', function() { 106 var itemPrice2 = 5076; 107 var itemPriceCount2 = $('[name="item2"] option:selected').text(); 108 $('[name="field2"]').val((parseInt(itemPrice2) * itemPriceCount2).toLocaleString()); 109 }); 110 111 } else { 112 $('[name="item2"] option').prop("selected", false); 113 $('[name="field2"]').val(0); 114 } 115 116 }); 117 118 119 $('[name=itemlist3]').click(function() { 120 if ($(this).is(':checked')) { 121 122 $('[name="item3"]').on('change', function() { 123 var itemPrice3 = 3780; 124 var itemPriceCount3 = $('[name="item3"] option:selected').text(); 125 $('[name="field3"]').val((parseInt(itemPrice3) * itemPriceCount3).toLocaleString()); 126 }); 127 128 } else { 129 $('[name="item3"] option').prop("selected", false); 130 $('[name="field3"]').val(0); 131 } 132 133 }); 134 135 $('[name=itemlist4]').click(function() { 136 if ($(this).is(':checked')) { 137 138 $('[name="item4"]').on('change', function() { 139 var itemPrice4 = 3780; 140 var itemPriceCount4 = $('[name="item4"] option:selected').text(); 141 $('[name="field4"]').val((parseInt(itemPrice4) * itemPriceCount4).toLocaleString()); 142 }); 143 144 } else { 145 $('[name="item4"] option').prop("selected", false); 146 $('[name="field4"]').val(0); 147 } 148 149 }); 150 151 $('[name=itemlist5]').click(function() { 152 if ($(this).is(':checked')) { 153 154 $('[name="item5"]').on('change', function() { 155 var itemPrice5 = 6156; 156 var itemPriceCount5 = $('[name="item5"] option:selected').text(); 157 $('[name="field5"]').val((parseInt(itemPrice5) * itemPriceCount5).toLocaleString()); 158 }); 159 160 } else { 161 $('[name="item5"] option').prop("selected", false); 162 $('[name="field5"]').val(0); 163 } 164 165 }); 166 167}); 168</script>
###補足情報(言語/FW/ツール等のバージョンなど)
HTMLのコードが長くなり1000文字を超えたので、こちらの質問ではHTMLは記載しておりません。
開発環境にてご確認して頂けると幸いです。
開発環境URL
https://cart-price-yujiokayama.c9users.io/index.html
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/10 08:20
退会済みユーザー
2017/04/12 14:25