回答編集履歴
1
コード追記
test
CHANGED
@@ -5,3 +5,99 @@
|
|
5
5
|
前回はロード時のみだったのが、どうして変わってしまったのでしょうか?
|
6
6
|
|
7
7
|
このスクリプトでは毎回時間かかりそうです。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
-- 13:12 コード追記
|
12
|
+
|
13
|
+
```HTML
|
14
|
+
|
15
|
+
<table>
|
16
|
+
|
17
|
+
<tbody>
|
18
|
+
|
19
|
+
<tr>
|
20
|
+
|
21
|
+
<th>商品のSKU</th><td><input type="text" name="sku" /></td><td>
|
22
|
+
|
23
|
+
<th>購入する数量</th><td><input type="text" name="quantity" /></td>
|
24
|
+
|
25
|
+
<td><input type="text" name="subtotal" size="8" value="0" /></td>
|
26
|
+
|
27
|
+
</tr>
|
28
|
+
|
29
|
+
<tr>
|
30
|
+
|
31
|
+
<th>商品のSKU</th><td><input type="text" name="sku" /></td><td>
|
32
|
+
|
33
|
+
<th>購入する数量</th><td><input type="text" name="quantity" /></td>
|
34
|
+
|
35
|
+
<td><input type="text" name="subtotal" size="8" value="0" /></td>
|
36
|
+
|
37
|
+
</tr>
|
38
|
+
|
39
|
+
<!-- 以下同様 -->
|
40
|
+
|
41
|
+
</tbody>
|
42
|
+
|
43
|
+
</table>
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```JavaScript
|
50
|
+
|
51
|
+
// csvArrayがある前提。
|
52
|
+
|
53
|
+
var rows = document.querySelector('form table tbody').rows;
|
54
|
+
|
55
|
+
var total = 0;
|
56
|
+
|
57
|
+
for (var i = 0; i < rows.length; i++) {
|
58
|
+
|
59
|
+
// SKU取得
|
60
|
+
|
61
|
+
var sku = rows[i].querySelector('[name="sku"]').value;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
// 数量
|
66
|
+
|
67
|
+
var qua = parseFloat(rows[i].querySelector('[name="quantity"]').value);
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// 重量取得スクリプト
|
72
|
+
|
73
|
+
var juryoget = -1;
|
74
|
+
|
75
|
+
var juryo = csvArray.filter(function(item, index){
|
76
|
+
|
77
|
+
if (item[1] === sku){
|
78
|
+
|
79
|
+
juryoget = item[2];
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
});
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// 重量と数量を掛けた物
|
88
|
+
|
89
|
+
var suryo = juryoget !== -1 ? juryoget * qua : 0;
|
90
|
+
|
91
|
+
rows[i].querySelector('[name="subtotal"]').value = suryo.toString();
|
92
|
+
|
93
|
+
total += suryo;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
document.form.result.value = total.toString();
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
入力されていない行がある等は考慮してください。
|