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.
<script type="text/javascript">
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 = '$' + util.formatCurrency(df[0].value * ppf);
df[2].value = '$' + util.formatCurrency(df[0].value * ppfTile);
df[3].value = '$' + util.formatCurrency(df[0].value * ppfVCTWood);
df[4].value = '$' + 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);
}
};
</script>
And here is the form.
<form name="carpet" action="#">
<div id="container">
<h2 style="font-size: 12pt;">
Cost Estimate</h2>
<label>
<input class="inp" type="text" />
: Enter Square Footage</label>
<br />
<label>
<input class="inp" type="text" value="$0" readonly="readonly" />
: Estimated Cost For Carpet</label>
<br />
<label>
<input class="inp" type="text" value="$0" readonly="readonly" />
: Estimated Cost For Tile </label>
<br />
<label>
<input class="inp" type="text" value="$0" readonly="readonly" />
: Estimated Cost For VCT and Wood </label>
<br />
<label>
<input class="inp" type="text" value="$0" readonly="readonly" />
: Estimated Cost For Travertine Tile </label>
<br />
<input type="reset" />
</div>
</form>
I am worried this is old and outdated. Could I do this more effectively with C# in the app?