체크한 것만 합계를 표시하는 스크립트
본문
<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>
출처 : http://www.aircon1004.com/data/bbs/board.php?bo_table=pds1&wr_id=178
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>
출처 : http://www.aircon1004.com/data/bbs/board.php?bo_table=pds1&wr_id=178
관련링크
댓글목록
등록된 댓글이 없습니다.