我有一个表单模板,我正在研究如何为产品添加更多字段(带有保管箱数量的大小)并计算所有大小的总和到总价计算,代码是这个
<script type="text/javascript">
JotForm.setConditions([{"action":[{"field":"2","visibility":"Hide"}],"index":0,"link":"Any","priority":"0","terms":[{"field":"4","operator":"isEmpty","value":false},{"field":"5","operator":"isEmpty","value":false},{"field":"13","operator":"isEmpty","value":false},{"field":"9","operator":"isEmpty","value":false}],"type":"field"}]);
JotForm.init(function(){
setTimeout(function() {
$('input_13').hint('ex: myname@example.com');
}, 20);
productID = {"0":"input_3_1001","1"};
paymentType = "product";
JotForm.setCurrencyFormat('BRL',true);
JotForm.totalCounter({"input_3_1001":{"price":"42","quantityField":"input_3_quantity_1001_0"}});
JotForm.highlightInputs = false;
});
HTML
<input class="form-checkbox" type="checkbox" id="input_3_1001" name="q3_input3[][id]" value="1001" />
<label for="input_3_1001">
Camisa Social Feminina Manga Curta
<br>
Branca/Detalhe Marinho (Panama)
<span class="form-product-details">
<b>
R$
<span id="input_3_1001_price">
42.00
</span>
</b>
</span>
</label>
<br />
<br />
<span class="form-sub-label-container">
<select class="form-dropdown" name="q3_input3[special_1001][item_0]" id="input_3_quantity_1001_0">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
<option value="7"> 7 </option>
<option value="8"> 8 </option>
<option value="9"> 9 </option>
<option value="10"> 10 </option>
</select>
<label class="form-sub-label" for="input_3_quantity_1001_0"> GG </label>
</span>
<span class="form-sub-label-container">
<select class="form-dropdown" name="q3_input3[special_1001][item_1]" id="input_3_custom_1001_1">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
<option value="7"> 7 </option>
<option value="8"> 8 </option>
<option value="9"> 9 </option>
<option value="10"> 10 </option>
</select>
<label class="form-sub-label" for="input_3_custom_1001_1"> GG2 </label>
</span>
</span>
答案 0 :(得分:0)
这个怎么样? (我将它简化为简单的Javascript)
<html>
<script type="text/javascript">
var prices = {item1:5.5, item2:32, item3:11.2, item4:33.7};
function getTotal() {
var total = 0;
for (id in prices) {
total += prices[id]*document.getElementById(id).value;
}
document.getElementById('total').innerHTML = total;
}
</script>
<body>
<input class="form-checkbox" type="checkbox" id="product" value="1001" />
Camisa Social Feminina Manga Curta
<br>
Branca/Detalhe Marinho (Panama)
<b>
R$
<span id="total">
0.00
</span>
</b>
<br>
<br>
<select id="item1" onchange="getTotal()">
<option>0<option>1<option>2<option>3<option>4<option>5<option>6<option>7<option>8<option>9<option>10</option>
</select>
<select id="item2" onchange="getTotal()">
<option>0<option>1<option>2<option>3<option>4<option>5<option>6<option>7<option>8<option>9<option>10</option>
</select>
<select id="item3" onchange="getTotal()">
<option>0<option>1<option>2<option>3<option>4<option>5<option>6<option>7<option>8<option>9<option>10</option>
</select>
<select id="item4" onchange="getTotal()">
<option>0<option>1<option>2<option>3<option>4<option>5<option>6<option>7<option>8<option>9<option>10</option>
</select>
</body>
</html>