Results 1 to 2 of 2

Thread: Comlpete Newb Basic Help (JavaScript?)

  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Comlpete Newb Basic Help (JavaScript?)

    Hi guys, i am a competent XHTML and CSS coder but i need a scirpt of somesort (javascript maybe?)

    All i need is a simple script which can count certain numbers. I have a form with 4 checkboxes which stand for certain amounts of money. I need the total to be displayed at the bottom of the form.

    So i need it to count the total of all the checkboxes that are ticked.(the amounts they stand for not the 'amount of checkboxes ticked')

    If anyone can point me in the right direction it would be great, i have no idea whatsoever how to do it I have spent all day yesterday and today reading w3 schools tut's to no avail.

    Any help is really appreciated.

    Cheers.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script  type="text/javascript">
    /*<![CDATA[*/
    
    function Total(obj,nme){
     var frm=obj.form;
     var cbs=frm[obj.name];
     for (var t=0,z0=0;z0<cbs.length;z0++){
      if (cbs[z0].checked){
       t+=cbs[z0].value*1;
      }
     }
     frm[nme].value=t;
    }
    /*]]>*/
    </script></head>
    
    <body>
    <form>
    
    <input type="checkbox" name="cb1" value="100" onclick="Total(this,'total1');"/>
    <input type="checkbox" name="cb1" value="150" onclick="Total(this,'total1');"/>
    <input name="total1" />
    </form>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Bookmarks

Posting Permissions

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