[제나플러스] 체크한 것만 합계를 표시하는 스크립트
본문
<script>
function sum(obj) {
var oColl = obj.form.elements;
var total = 0;
for (var i=0; i < oColl.length; i++) {
if (oColl[i].name.substr(0,4)=="item" && oColl[i].checked)
total += parseInt(oColl[i].price);
}
obj.form.total.value = total;
}
</script>
<form>
<input type=checkbox name=item1 price=100 onClick="sum(this)">100원짜리<br>
<input type=checkbox name=item2 price=120 onClick="sum(this)">120원짜리<br>
<input type=checkbox name=item3 price=150 onClick="sum(this)">150원짜리<br>
<input type=text name=total value=0 readonly>
</form>
function sum(obj) {
var oColl = obj.form.elements;
var total = 0;
for (var i=0; i < oColl.length; i++) {
if (oColl[i].name.substr(0,4)=="item" && oColl[i].checked)
total += parseInt(oColl[i].price);
}
obj.form.total.value = total;
}
</script>
<form>
<input type=checkbox name=item1 price=100 onClick="sum(this)">100원짜리<br>
<input type=checkbox name=item2 price=120 onClick="sum(this)">120원짜리<br>
<input type=checkbox name=item3 price=150 onClick="sum(this)">150원짜리<br>
<input type=text name=total value=0 readonly>
</form>
추천0
관련링크
댓글목록 0
등록된 댓글이 없습니다.