Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question counting check boxes

    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!

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,503
    Thanks
    3
    Thanked 500 Times in 487 Posts
    PHP Code:

    <!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> 

  • #3
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just what I need! thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •