Cost Calculation Function With Parsed Numbers to Currency: Need Help Combining Functions

Discussion in 'HTML' started by Neredbojias, Oct 3, 2005.

  1. Neredbojias

    Neredbojias Guest

    With neither quill nor qualm, Fred quothed:
    It should be easy to strip the $ before processing, no??
     
    Neredbojias, Oct 3, 2005
    #1
    1. Advertisements

  2. Neredbojias

    Fred Guest

    I'm trying to validate this script so the number entered is parsed
    and a dollar sign is automatically entered before the number onBlur.

    My problem is that when I do this, the script interoperates the dollar
    sign as a character and not a numerical number and the script crashes
    (NaN).

    FYI: When I tested it, I executed the funtion via a double onBlur
    call from the text box.

    My best guess to resolving the issue is to insert the function within
    the script. How would I go about doing this with out crashing
    function calc()}?


    // Here's the working calculation functions - - - - - -
    // Here's the working calculation functions - - - - - -
    // Here's the working calculation functions - - - - - -

    function startCalc(){
    interval = setInterval("calc()",1);
    }
    function calc(){
    one = document.autoSumForm.firstBox.value;
    two = document.autoSumForm.secondBox.value;
    three = document.autoSumForm.thirdBox.value;
    four = document.autoSumForm.fourthBox.value;
    five = document.autoSumForm.fithBox.value;
    six = document.autoSumForm.sixthBox.value;
    var totalCost = (one * 1) + (two * 1) + (three * 1) + (four * 1) +
    (five * 1) + (six * 1);
    document.autoSumForm.seventhBox.value = totalCost;
    var fee = document.autoSumForm.TotalServiceFee.value;
    if ( fee != "" ) {
    var monthlySavings = totalCost - parseFloat(fee);
    var yearlySavings = monthlySavings * 12;
    document.autoSumForm.TotalMonthlySavings.value =
    monthlySavings;
    document.autoSumForm.TotalYearlySavings.value = ("" +
    yearlySavings).replace(/(\.[0-9]{2}).*$/g, "$1");
    }

    }
    function stopCalc(){
    clearInterval(interval);
    }
    function fillUp(radioBtn) {
    document.autoSumForm.TotalServiceFee.value = radioBtn.value;
    calc();


    }





    // Here's the working parse number to currency functions - -
    // Here's the working parse number to currency functions - -
    // Here's the working parse number to currency functions - -

    var prefix="$"
    var wd

    function parseelement(thisone){
    if (thisone.value.charAt(0)=="$")
    return
    wd="w"
    var tempnum=thisone.value
    for (i=0;i<tempnum.length;i++){
    if (tempnum.charAt(i)=="."){
    wd="d"
    break
    }

    }
    if (wd=="w")
    thisone.value=prefix+tempnum+".00"
    else{

    if (tempnum.charAt(tempnum.length-2)=="."){
    thisone.value=prefix+tempnum+"0"
    }
    else{
    tempnum=Math.round(tempnum*100)/100
    thisone.value=prefix+tempnum
    }
    }
    }



    How do I merge these two???
     
    Fred, Oct 3, 2005
    #2
    1. Advertisements

  3. Neredbojias

    Fred Guest


    I was thinking after processig.

    How would you do it? Can you post an example?
     
    Fred, Oct 4, 2005
    #3
  4. Neredbojias

    Neredbojias Guest

    With neither quill nor qualm, Fred quothed:
    Well, in javascript it'd be simply:

    var a;
    ....
    ....
    a=a.slice(1);

    (You could also use regexp replace.)

    If you have to verify whether or not the "$" is there:

    if (a.slice(0,1)=="$") {
    a=a.slice(1);
    }

    There's similar functions in php, etc.
     
    Neredbojias, Oct 4, 2005
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.