SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2000
    Location
    UK
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calculating totals with select boxes!??

    Could someone please help me. I am desperate to get this working.

    I am trying to create a calculator that can calculate the total cost of something using select menus. I have managed to do it with one item, no problem, but when it comes to calculating multiple items in one form, I get errors all over the place.

    Here is an example of what I need; http://allaccessdomains.com/allaccess.html

    Take a look at the select boxes at the bottom of the page and mess about with them and you will see what I mean. Feel free to mess with the source code aswell.

    As I said it works fine with just one select box and one item, but not with multiple.

    I would appreciate it greatly if someone could help me out here.

    Thanks,
    Joel Moss
    ========================
    HomepageUniverse - Names, Tools & Hosting

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    View Source

    If you view the source code, its all there.

    Good Luck

    <SCRIPT language=JavaScript>
    <!-- Begin
    function checkChoice(whichbox) {
    with (whichbox.form) {
    if (isNaN(whichbox.value)) {
    whichbox.value = whichbox.priorval;
    whichbox.focus();
    }
    whichbox.value = Math.abs(whichbox.value);
    var dec = whichbox.value.indexOf('.', 1)
    if (dec > 0) {
    alert('No decimal places allowed for \"' +whichbox.name +'\" !');
    whichbox.value = whichbox.priorval;
    whichbox.focus();
    }
    hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
    whichbox.priorval = whichbox.value;
    hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
    return(formatCurrency(hiddentotal.value));
    }
    }
    function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";
    cents = Math.floor((num * 100 + 0.5) % 100);
    num = Math.floor((num * 100 + 0.5) / 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 ("$" + num + "." + cents);
    }
    function InitForm() {
    //document.myform.total.value = '$0';
    //document.myform.hiddentotal.value = 0;
    for (xx = 0; xx < document.myform.elements.length; xx++) {
    if (document.myform.elements[xx].type == 'text') {
    document.myform.elements[xx].value = 0;
    }
    }
    }
    // End -->
    </SCRIPT>


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
  •