|
Posted by Fred on 12/05/47 11:28
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???
Navigation:
[Reply to this message]
|