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 to the CF scene
    Join Date
    Sep 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    one checkbox -- 2 total boxes

    Hey all

    I have a script that Im using that came from a free Javascript site. It works great as is for totalling up one column. I would really like for it to also total another column at the same time, using just the one checkbox if possible. I hope I'm making some kind of sense here.

    You can see it in action here . I'm hoping someone can advise me on how to make another total box at the bottom that counts the "channel" column as well as the price column.

    Thanks for any advice or help.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Could you post the code thats relevent to that part of your page...i'm sure you'll get more responses if they dont have to view source to find the code...

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sure thing...its a biggun.


    <script type="text/javascript" language="javascript">

    <!-- Begin
    function CheckChoice(whichbox)
    {
    with (whichbox.form)
    {
    //Handle differently, depending on type of input box.
    if (whichbox.type == "radio")
    {
    //First, back out the prior radio selection's price from the total:
    hiddentotal.value = eval(hiddentotal.value) - eval(hiddenpriorradio.value);
    //Then, save the current radio selection's price:
    hiddenpriorradio.value = eval(whichbox.price);
    //Now, apply the current radio selection's price to the total:
    hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price);
    }
    else
    {
    //If box was checked, accumulate the checkbox value as the form total,
    //Otherwise, reduce the form total by the checkbox value:
    if (whichbox.checked == false)
    { hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value); }
    else { hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value); }
    }

    //Ensure the total never goes negative (some browsers allow radiobutton to be deselected):
    if (hiddentotal.value < 0)
    {
    InitForm();
    }

    //Now, return with formatted total:
    return(formatCurrency(hiddentotal.value));
    }
    }

    //Define function to format a value as currency:
    function formatCurrency(num)
    {
    // Courtesy of http://www7.brinkster.com/cyanide7/
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
    }

    //Define function to init the form on reload:
    function InitForm()
    {
    //Reset the displayed total on form:
    document.myform.total.value='$0';
    document.myform.hiddentotal.value=0;
    document.myform.hiddenpriorradio.value=0;
    document.myform2.total.value='$0';
    document.myform2.hiddentotal.value=0;
    document.myform2.hiddenpriorradio.value=0;
    document.myform2.hiddenpriorradio.value=0;

    //Set all checkboxes and radio buttons on form-1 to unchecked:
    for (xx=0; xx < document.myform.elements.length; xx++)
    {
    if (document.myform.elements[xx].type == 'checkbox' | document.myform.elements[xx].type == 'radio')
    {
    document.myform.elements[xx].checked = false;
    }
    }
    //Set all checkboxes and radio buttons on form-2 to unchecked:
    for (xx=0; xx < document.myform2.elements.length; xx++)
    {
    if (document.myform2.elements[xx].type == 'checkbox' | document.myform2.elements[xx].type == 'radio')
    {
    document.myform2.elements[xx].checked = false;
    }
    }

    }
    </script>


    <BODY onLoad="InitForm();" onreset="InitForm();">

    <form method="POST" name="myform">

    <input type="checkbox" name="Basic1" value=13.25
    onclick="this.form.total.value=CheckChoice(this);">


  •  

    Posting Permissions

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