...

View Full Version : counting check boxes



noviceNate
03-21-2005, 08:41 PM
I have a form with several check boxes. The user can choose up to 5 boxes for a price of $100. However, for each additional box checked over 5, an additional $25 is added to their bill. So, how can I set that up that not only does it keep count, but once they go over the 5, a price is updated as well? Thanks in advance!

vwphillips
03-21-2005, 09:34 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var cbs,cnt;

function InitCB(id){
cbs=document.getElementById(id).getElementsByTagName('INPUT');
for (i=0;i<cbs.length;i++){
if (document.all){
cbs[i].onclick=function(){ Count(); }
}
else {
cbs[i].setAttribute('onclick','javascript:Count();');
}
}
}

function Count(){
total=100;
cnt=0;
for (i=0;i<cbs.length;i++){
if (cbs[i].checked){
cnt++;
}
}
if (cnt>5){
total+=(cnt-5)*25;
}
document.getElementById('Cost').value='$'+total;
}


//-->
</script>

</head>

<body onload="InitCB('CB');" >
<div id="CB" >
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
<input type="checkbox" name=""><br>
</div>
<input id="Cost" value="" size="10">
</body>

</html>

noviceNate
03-21-2005, 09:45 PM
Just what I need! thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum