HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Calculator for calculating price per feet amounts

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
pricepercalculatingfeetamountsforcalculator

Problem

So I have a customers site I am remaking into an mvc3 app and they have an existing JavaScript pricing calculator. Is this safe and efficient? I am no JavaScript guy, but it looks pretty solid to me.


    window.onload = function () {

        //Carpet
        var ppf = .25; //price per square foot, edit this to suit
        //tile
        var ppfTile = .50; //price per square foot, edit this to suit
        var ppfVCTWood = .60; //price per square foot, edit this to suit
        var ppfTravertine = .60; //price per square foot, edit this to suit

        df = document.carpet;
        df[0].focus();
        df[2].onclick = function () {
            df[0].focus();
        };
        df[0].onkeyup = function () {
            if (isNaN(df[0].value)) {
                alert('numbers only please');
                df.reset();
                df[0].focus();
                return;
            }
            df[1].value = '

And here is the form.


    
        Cost Estimate
    
        
        : Enter Square Footage
    
    
        
        : Estimated Cost For Carpet
    
    
    
    : Estimated Cost For Tile 
    
    
    
    : Estimated Cost For VCT and Wood 
    
    
    
    : Estimated Cost For Travertine Tile 
    
    


I am worried this is old and outdated. Could I do this more effectively with C# in the app? + util.formatCurrency(df[0].value * ppf); df[2].value = '

And here is the form.

%%CODEBLOCK_1%%

I am worried this is old and outdated. Could I do this more effectively with C# in the app? + util.formatCurrency(df[0].value * ppfTile); df[3].value = '

And here is the form.

%%CODEBLOCK_1%%

I am worried this is old and outdated. Could I do this more effectively with C# in the app? + util.formatCurrency(df[0].value * ppfVCTWood); df[4].value = '

And here is the form.

%%CODEBLOCK_1%%

I am worried this is old and outdated. Could I do this more effectively with C# in the app? + util.formatCurrency(df[0].value * ppfTravertine); }; }; var util = { formatCurrency: function (num) { num = isNaN(num) || num === '' || num === null ? 0.00 : num; return parseFloat(num).toFixed(2); } };


And here is the form.

%%CODEBLOCK_1%%

I am worried this is old and outdated. Could I do this more effectively with C# in the app?

Solution

About the only thing that I don't like in it is that you have to edit the code each time a price changes. I'd prefer that to come from a dynamic source, especially if you are going to use it in more than one spot.

Context

StackExchange Code Review Q#13201, answer score: 3

Revisions (0)

No revisions yet.