function isBlank(varString) { var boolStringIsBlank = true var intI if(varString) {
for(intI=0; intI < varString.length; intI++) { if(varString.charAt(intI) != " ") { boolStringIsBlank = false break } } } return boolStringIsBlank } function doCalc() { var boolPerform = true var strMsg var intDepth var intArea var sngResult if(isBlank(document.MulchCalc.thickness.value)) { boolPerform = false strMsg = "Thickness is required." document.MulchCalc.thickness.focus() } if(boolPerform) if(isBlank(document.MulchCalc.area.value)) { boolPerform = false strMsg = "Total Area is required." document.MulchCalc.area.focus() } if(boolPerform) { intDepth = document.MulchCalc.thickness.value intArea = document.MulchCalc.area.value // The following comments relate to the calculation that follows them: // Multiply area by 144 to convert to square inches. // Assume 46656 cubic inches to the cubic yard... // 27 cubic feet per cubic yard // x 1728 cubic inches per cubic foot // = 46656 cubic inches per cubic yard // Before rounding, multiply by 100 (144 becomes 14400) to preserve 2 decimal positions. // After rounding, divide by 100 to restore the 2 decimal positions. sngResult = Math.round((intDepth * intArea * 14400) / 46656) / 100 document.MulchCalc.Total.value = sngResult } else alert(strMsg) }