<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module 2</title>
</head>
<body>
<?php
$widths = array(0 => 20,30,20,40,50,30,50,30);
$heights = array(0 =>9,9,9,9,10,10,10,10);
$rates = array('PROFESSIONAL'=>17.50,'REGULAR'=>12.50);
$types = array('FLAT'=>24.00,'SATIN'=>31.50,'GLOSS'=>27.75);
DEFINE('COVERAGE',310);
DEFINE('TIME',8);
$index=0;
$totalTime=0;
$totalGal = 0;
?>
<SCRIPT Language="JavaScript">
<!--
var acover = 310; // application paint coverage per gallon of paint in square feet
var afeet = 0; // actual square footage of wall
var identnum = 0; // number of IDENTICAL walls
var pfeet = 0; // actual paintable square feet - no adjustments for texture or coats
var laborratereg = 0; //
var laborratepro = 0; //
var hours = 0; //
var length = 0; //
var width = 0; //
var height = 0; //
var recalc = 0; //
function calcRound(num, precision) {
var precision = 2; //default value if not passed from caller, change if desired
// remark if passed from caller
precision = parseInt(precision); // make certain the decimal precision is an integer
var result1 = num * Math.pow(10, precision);
var result2 = Math.round(result1);
var result3 = result2 / Math.pow(10, precision);
return zerosPad(result3, precision);
}
function zerosPad(rndVal, decPlaces) {
var valStrg = rndVal.toString(); // Convert the number to a string
var decLoc = valStrg.indexOf("."); // Locate the decimal point
// check for a decimal
if (decLoc == -1) {
decPartLen = 0; // If no decimal, then all decimal places will be padded with 0s
// If decPlaces is greater than zero, add a decimal point
valStrg += decPlaces > 0 ? "." : "";
}
else {
decPartLen = valStrg.length - decLoc - 1; // If there is a decimal already, only the needed decimal places will be padded with 0s
}
var totalPad = decPlaces - decPartLen; // Calculate the number of decimal places that need to be padded with 0s
if (totalPad > 0) {
// Pad the string with 0s
for (var cntrVal = 1; cntrVal <= totalPad; cntrVal++)
valStrg += "0";
}
return valStrg;
}
// send the value in as "num" in a variable
// clears field of default value
function clear_field(field) {
if (field.value==field.defaultValue) {
field.value=''
}
}
// make sure it is a number or a decimal
function ValidateNumber(rVal)
{
inLen = rVal.length;
for(var i=0; i<inLen; i++) {
var ch = rVal.substring(i,i+1);
if (! (ch> "0" || "9"> ch || ch == ".") )
{
alert("Entry incorrect, please re-enter");
return -1;
}
}
return rVal;
}
function ValidateJob()
{
ExecuteJob();
if (gallonsc > gallons) {
gallons = Math.round(gallons) + 1;
} // make sure you buy enough application paint!!!!
else {
gallons = Math.round(gallons);
}
if (bgallonsc > bgallons) {
bgallons = Math.round(bgallons) + 1;
} // make sure you buy enough base paint!!!!
else {
bgallons = Math.round(bgallons);
}
document.PaintForm.wallsqfeetc.value = afeet; // basic wall square feet
document.PaintForm.sqfeet.value = feet; // rounded paintable square feet after options applications
document.PaintForm.paintgals.value = gallons; // purchase quantity application
document.PaintForm.sqfeetc.value = feetc; //square feet calculated for application after options
document.PaintForm.paintgalsc.value = gallonsc;
document.PaintForm.paintbgalsc.value = bgallonsc;
document.PaintForm.pexpense.value = calcRound(gallons * pexpense);
document.PaintForm.laborexpense.value = calcRound(cost * time);
document.PaintForm.paintexpense.value = calcRound((gallons * pexpense) + (bgallons * pbexpense));
document.PaintForm.allexpense.value = calcRound((gallons * pexpense) + (bgallons * pbexpense) + (cost * time));
}
function ExecuteJob()
{
var width = ValidateNumber(document.PaintForm.width.value); // check input
if (width == -1) { // -1 means invalid input
document.PaintForm.width.value = 0;// reset form field
width = 0; // zero out variable
}
var length = ValidateNumber(document.PaintForm.length.value);
if (length == -1) {
document.PaintForm.length.value = 0;
length = 0;
}
var height = ValidateNumber(document.PaintForm.height.value);
if (height == -1) {
document.PaintForm.height.value = 0;
height = 0;
}
var acover = ValidateNumber(document.PaintForm.acover.value);
if (acover == -1) {
document.PaintForm.acover.value = 0;
acover = 0;
}
var identnum = ValidateNumber(document.PaintForm.identnum.value);
if (identnum == -1) {
document.PaintForm.identnum.value = 0;
identnum = 0;
}
afeet = (identnum * (height * width)) + (identnum * (height * length)); // actual square footage of wall - no ceiling
var areadoor = 21; // square feet of average door
var qtydoor = ValidateNumber(document.PaintForm.qtydoor.value);
if (qtydoor == -1) {
document.PaintForm.qtydoor.value = 0;
qtydoor = 0;
}
var areawin = 16; // square feet of average window
var qtywin = ValidateNumber(document.PaintForm.qtywin.value);
if (qtywin == -1) {
document.PaintForm.qtywin.value = 0;
qtywin = 0;
}
pfeet = (afeet - (qtydoor * areadoor) - (qtywin * areawin)); // actual paintable square feet - no adjustments for texture or coats
var pcost = ValidateNumber(document.PaintForm.pcost.value); // decimal
if (pcost == -1) { // -1 means invalid input
document.PaintForm.pcost.value = 0;
pcost = 0; // cost per gallon of application paint
}
var bcost = ValidateNumber(document.PaintForm.bcost.value); // decimal
if (bcost == -1) { // -1 means invalid input
document.PaintForm.bcost.value = 0;
bcost = 0; // cost per gallon of base paint
}
var laborrate = ValidateNumber(document.PaintForm.laborrate.value); // decimal
if (laborrate == -1) { // -1 means invalid input
document.PaintForm.laborrate.value = 0;
laborrate = 0; // cost per hour to paint
}
var hours = ValidateNumber(document.PaintForm.hours.value); // decimal
if (hours == -1) { // -1 means invalid input
document.PaintForm.hours.value = 0;
hours = 0; // estimated hours to paint
}
calcRound (laborrate); //format money to 2 decimal places
cost = laborrate; // base coat no or yes, default is no
calcRound (hours); //format to 2 decimal places
time = hours; // base coat no or yes, default is no
calcRound (pcost); //format money to 2 decimal places
pexpense = pcost; // application coats 1 or 2, default is 1
if (document.PaintForm.qtyapps[1].checked)
{
qtyapps = 2;
}
else
{
qtyapps = 1;
}
calcRound (bcost); //format money to 2 decimal places
pbexpense = bcost; // base coat no or yes, default is no
if (document.PaintForm.incbaseapp[0].checked)
{
qtybapps = 0;
}
else
{
qtybapps = 1;
}
if (document.PaintForm.wayapps[0].checked)
{
wayapps = 1.15; // spraying = 15% more material
}
else
{
wayapps = 1; // rolled or brushed
}
feet = (identnum * (height * width)) + (identnum * (height * length));
feet = (feet - (qtydoor * areadoor) - (qtywin * areawin));//number of feet painted no texture wall
if (document.PaintForm.wallt.checked) {
feet = feet + (feet * .16); // textured walls each wall .04 increase
}
if (document.PaintForm.wallht.checked) {
feet = feet + ( feet * .32); // heavily textured walls each wall .08 increase
}
if (document.PaintForm.verydry.checked) {
feet = feet + ( feet * .20); // very dry climate .20 increase
}
feet = (feet * wayapps);//number of application coat feet based on method after other extras
bfeet = (feet * wayapps);//number of base coat based on method after other extras
feet = (feet * qtyapps);//number of application coat feet based on application coats after other extras
bfeet = (bfeet * qtybapps);//number of base coat feet based on one or no coats after other extras
if (feet> 0) {
gallonsc = ((feet / acover) + .80);
gallons = Math.round((feet / acover) + .80);
feetc = (feet);
feet = Math.round(feet);
}
else {
feet = 0;
feetc = 0;
gallons =0;
gallonsc =0;
// application
}
if (bfeet > 0) {
bgallonsc = ((bfeet / bcover) + .90);
bgallons = Math.round((bfeet / bcover) + .90);
bfeetc = (bfeet);
bfeet = Math.round(bfeet);
}
else {
bgallons = 0;
bgallonsc = 0;
// base coat
}
}
// -->
</SCRIPT>
</HEAD>
<NOSCRIPT>
This document requires JavaScript enabled browsers; verify that yours is capable and perhaps only turned off.
</NOSCRIPT>
<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>
<h1><center>Module 2</center></h1>
<td>
<TABLE ALIGN="center" BORDER=5 CELLPADDING=5>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Wall Design</b>
</td>
</tr>
<tr>
<!--ROW 1-->
<td>Wall Height</td>
<td>
<input maxlength="6" name="height" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<tr>
<td>Wall Width</td>
<td>
<input maxlength="6" name="width" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<TR bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Anticipated Paint Coverage</b></td>
<tr>
<td>Application Coat Coverage Square Feet</td>
<td>
<input maxlength="6" name="acover" value="310" onChange=ValidateJob(); size="6"> Per Gallon
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Rate</b></td>
</tr>
<tr>
<td>Regular</td>
<td>
<input CHECKED name="typrate" type="radio" value="12.50">
</td>
</tr>
<tr>
<td>Professional</td>
<td>
<input name="typrate" type="radio" value="17.50">
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Paint</b></td>
</tr>
<tr>
<td>Flat</td>
<td>
<input CHECKED name="qtyapps" type="radio" value="24">
</td>
</tr>
<tr>
<td>Satin</td>
<td>
<input name="qtyapps" type="radio" value="31.50">
</td>
</tr>
<tr >
<td>Gloss</td>
<td>
<input name="incbaseapp" type="radio" value="27.75">
</td>
</tr>
<tr>
<td>Semi Gloss</td>
<td>
<input name="incbaseapp" type="radio" value="27.75">
</td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#B6D4D2">
<input onClick=ValidateJob(); type="button" value="Calculate" name="button">
<input type="submit" value="Clear Values" name="submit"><br>
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Calculated Results</b>
</td>
</tr>
<tr>
<td>Basic Wall Square Footage</td>
<td>
<input maxlength="18" name="wallsqfeetc" size="18">
</td>
</tr>
<tr>
<td>Rounded Application Paintable Square Footage</td>
<td>
<input maxlength="4" name="sqfeet" size="4">
</td>
</tr>
<tr>
<td>Calculated Application Paintable Square Footage</td>
<td>
<input maxlength="18" name="sqfeetc" size="18">
</td>
</tr>
<tr>
<td>Approximate Gallons Of Application Paint To Purchase</td>
<td>
<input maxlength="6" name="paintgals" size="6">
</td>
</tr>
<tr>
<td>Calculated Gallons Of Application Paint Required</td>
<td>
<input maxlength="18" name="paintgalsc" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of Application Paint Required</td>
<td>
$<input maxlength="18" name="pexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of All Paint Required</td>
<td>
$<input maxlength="18" name="paintexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of Labor Required</td>
<td>
$<input maxlength="18" name="laborexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Total Expense Of This Wall Or Walls</td>
<td>
$<input maxlength="18" name="allexpense" size="18">
</td>
</tr>
</body>
</html>
11 replies to this topic
#1
Posted 18 January 2011 - 02:40 PM
Okay so I am doing a project for school where the user is supposed to input some numbers and then it is supposed to calculate all fields and display the output. It is for a "paint company". The problem I am facing is that it isn't outputting anything. Any help would be appreciated.
|
|
|
#2
Posted 18 January 2011 - 03:21 PM
what is length field?
and where is the "identnum" filed?
it must be something like <input name="length", and <input name="identnum"...
where did you get this code? it's incomplete!
and where is the "identnum" filed?
it must be something like <input name="length", and <input name="identnum"...
where did you get this code? it's incomplete!
#3
Posted 18 January 2011 - 03:29 PM
It was bits and pieces from the teacher. She is wanting us to put it together and complete it. I will work on it some more and then post what I have after I clean it up
#4
Posted 18 January 2011 - 03:42 PM
#5
Posted 18 January 2011 - 03:50 PM
okay, i kina completed it. fixed some how!
those inputs with orange background added by me!
those inputs with orange background added by me!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module 2</title>
</head>
<body>
<?php
$widths = array(0 => 20,30,20,40,50,30,50,30);
$heights = array(0 =>9,9,9,9,10,10,10,10);
$rates = array('PROFESSIONAL'=>17.50,'REGULAR'=>12.50);
$types = array('FLAT'=>24.00,'SATIN'=>31.50,'GLOSS'=>27.75);
DEFINE('COVERAGE',310);
DEFINE('TIME',8);
$index=0;
$totalTime=0;
$totalGal = 0;
?>
<SCRIPT Language="JavaScript">
<!--
var bcover = 1;
var acover = 310; // application paint coverage per gallon of paint in square feet
var afeet = 0; // actual square footage of wall
var identnum = 0; // number of IDENTICAL walls
var pfeet = 0; // actual paintable square feet - no adjustments for texture or coats
var laborratereg = 0; //
var laborratepro = 0; //
var hours = 0; //
var length = 0; //
var width = 0; //
var height = 0; //
var recalc = 0; //
function calcRound(num, precision) {
var precision = 2; //default value if not passed from caller, change if desired
// remark if passed from caller
precision = parseInt(precision); // make certain the decimal precision is an integer
var result1 = num * Math.pow(10, precision);
var result2 = Math.round(result1);
var result3 = result2 / Math.pow(10, precision);
return zerosPad(result3, precision);
}
function zerosPad(rndVal, decPlaces) {
var valStrg = rndVal.toString(); // Convert the number to a string
var decLoc = valStrg.indexOf("."); // Locate the decimal point
// check for a decimal
if (decLoc == -1) {
decPartLen = 0; // If no decimal, then all decimal places will be padded with 0s
// If decPlaces is greater than zero, add a decimal point
valStrg += decPlaces > 0 ? "." : "";
}
else {
decPartLen = valStrg.length - decLoc - 1; // If there is a decimal already, only the needed decimal places will be padded with 0s
}
var totalPad = decPlaces - decPartLen; // Calculate the number of decimal places that need to be padded with 0s
if (totalPad > 0) {
// Pad the string with 0s
for (var cntrVal = 1; cntrVal <= totalPad; cntrVal++)
valStrg += "0";
}
return valStrg;
}
// send the value in as "num" in a variable
// clears field of default value
function clear_field(field) {
if (field.value==field.defaultValue) {
field.value=''
}
}
// make sure it is a number or a decimal
function ValidateNumber(rVal)
{
inLen = rVal.length;
for(var i=0; i<inLen; i++) {
var ch = rVal.substring(i,i+1);
if (! (ch> "0" || "9"> ch || ch == ".") )
{
alert("Entry incorrect, please re-enter");
return -1;
}
}
return rVal;
}
function ValidateJob()
{
ExecuteJob();
if (gallonsc > gallons) {
gallons = Math.round(gallons) + 1;
} // make sure you buy enough application paint!!!!
else {
gallons = Math.round(gallons);
}
if (bgallonsc > bgallons) {
bgallons = Math.round(bgallons) + 1;
} // make sure you buy enough base paint!!!!
else {
bgallons = Math.round(bgallons);
}
document.PaintForm.wallsqfeetc.value = afeet; // basic wall square feet
document.PaintForm.sqfeet.value = feet; // rounded paintable square feet after options applications
document.PaintForm.paintgals.value = gallons; // purchase quantity application
document.PaintForm.sqfeetc.value = feetc; //square feet calculated for application after options
document.PaintForm.paintgalsc.value = gallonsc;
document.PaintForm.paintbgalsc.value = bgallonsc;
document.PaintForm.pexpense.value = calcRound(gallons * pexpense);
document.PaintForm.laborexpense.value = calcRound(cost * time);
document.PaintForm.paintexpense.value = calcRound((gallons * pexpense) + (bgallons * pbexpense));
document.PaintForm.allexpense.value = calcRound((gallons * pexpense) + (bgallons * pbexpense) + (cost * time));
}
function ExecuteJob()
{
var width = ValidateNumber(document.PaintForm.width.value); // check input
if (width == -1) { // -1 means invalid input
document.PaintForm.width.value = 0;// reset form field
width = 0; // zero out variable
}
var length = ValidateNumber(document.PaintForm.length.value);
if (length == -1) {
document.PaintForm.length.value = 0;
length = 0;
}
var height = ValidateNumber(document.PaintForm.height.value);
if (height == -1) {
document.PaintForm.height.value = 0;
height = 0;
}
var acover = ValidateNumber(document.PaintForm.acover.value);
if (acover == -1) {
document.PaintForm.acover.value = 0;
acover = 0;
}
var identnum = ValidateNumber(document.PaintForm.identnum.value);
if (identnum == -1) {
document.PaintForm.identnum.value = 0;
identnum = 0;
}
afeet = (identnum * (height * width)) + (identnum * (height * length)); // actual square footage of wall - no ceiling
var areadoor = 21; // square feet of average door
var qtydoor = ValidateNumber(document.PaintForm.qtydoor.value);
if (qtydoor == -1) {
document.PaintForm.qtydoor.value = 0;
qtydoor = 0;
}
var areawin = 16; // square feet of average window
var qtywin = ValidateNumber(document.PaintForm.qtywin.value);
if (qtywin == -1) {
document.PaintForm.qtywin.value = 0;
qtywin = 0;
}
pfeet = (afeet - (qtydoor * areadoor) - (qtywin * areawin)); // actual paintable square feet - no adjustments for texture or coats
var pcost = ValidateNumber(document.PaintForm.pcost.value); // decimal
if (pcost == -1) { // -1 means invalid input
document.PaintForm.pcost.value = 0;
pcost = 0; // cost per gallon of application paint
}
var bcost = ValidateNumber(document.PaintForm.bcost.value); // decimal
if (bcost == -1) { // -1 means invalid input
document.PaintForm.bcost.value = 0;
bcost = 0; // cost per gallon of base paint
}
var laborrate = ValidateNumber(document.PaintForm.laborrate.value); // decimal
if (laborrate == -1) { // -1 means invalid input
document.PaintForm.laborrate.value = 0;
laborrate = 0; // cost per hour to paint
}
var hours = ValidateNumber(document.PaintForm.hours.value); // decimal
if (hours == -1) { // -1 means invalid input
document.PaintForm.hours.value = 0;
hours = 0; // estimated hours to paint
}
calcRound (laborrate); //format money to 2 decimal places
cost = laborrate; // base coat no or yes, default is no
calcRound (hours); //format to 2 decimal places
time = hours; // base coat no or yes, default is no
calcRound (pcost); //format money to 2 decimal places
pexpense = pcost; // application coats 1 or 2, default is 1
if (document.PaintForm.qtyapps[1].checked)
{
qtyapps = 2;
}
else
{
qtyapps = 1;
}
calcRound (bcost); //format money to 2 decimal places
pbexpense = bcost; // base coat no or yes, default is no
if (document.PaintForm.incbaseapp[0].checked)
{
qtybapps = 0;
}
else
{
qtybapps = 1;
}
if (document.PaintForm.wayapps[0].checked)
{
wayapps = 1.15; // spraying = 15% more material
}
else
{
wayapps = 1; // rolled or brushed
}
feet = (identnum * (height * width)) + (identnum * (height * length));
feet = (feet - (qtydoor * areadoor) - (qtywin * areawin));//number of feet painted no texture wall
if (document.PaintForm.wallt.checked) {
feet = feet + (feet * .16); // textured walls each wall .04 increase
}
if (document.PaintForm.wallht.checked) {
feet = feet + ( feet * .32); // heavily textured walls each wall .08 increase
}
if (document.PaintForm.verydry.checked) {
feet = feet + ( feet * .20); // very dry climate .20 increase
}
feet = (feet * wayapps);//number of application coat feet based on method after other extras
bfeet = (feet * wayapps);//number of base coat based on method after other extras
feet = (feet * qtyapps);//number of application coat feet based on application coats after other extras
bfeet = (bfeet * qtybapps);//number of base coat feet based on one or no coats after other extras
if (feet> 0) {
gallonsc = ((feet / acover) + .80);
gallons = Math.round((feet / acover) + .80);
feetc = (feet);
feet = Math.round(feet);
}
else {
feet = 0;
feetc = 0;
gallons =0;
gallonsc =0;
// application
}
if (bfeet > 0) {
bgallonsc = ((bfeet / bcover) + .90);
bgallons = Math.round((bfeet / bcover) + .90);
bfeetc = (bfeet);
bfeet = Math.round(bfeet);
}
else {
bgallons = 0;
bgallonsc = 0;
// base coat
}
}
// -->
</SCRIPT>
</HEAD>
<NOSCRIPT>
This document requires JavaScript enabled browsers; verify that yours is capable and perhaps only turned off.
</NOSCRIPT>
<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>
<form name="PaintForm">
<h1><center>Module 2</center></h1>
<td>
<TABLE ALIGN="center" BORDER=5 CELLPADDING=5>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Wall Design</b>
</td>
</tr>
<tr>
<!--ROW 1-->
<td>Wall Height</td>
<td>
<input maxlength="6" name="height" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<tr>
<td>Wall Width</td>
<td>
<input maxlength="6" name="width" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<TR bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Anticipated Paint Coverage</b></td>
<tr>
<td>Application Coat Coverage Square Feet</td>
<td>
<input maxlength="6" name="acover" value="310" onChange=ValidateJob(); size="6"> Per Gallon
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>Length</td>
<td>
<input maxlength="6" name="length" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>identnum</td>
<td>
<input maxlength="6" name="identnum" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>qtydoor</td>
<td>
<input maxlength="6" name="qtydoor" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>qtywin</td>
<td>
<input maxlength="6" name="qtywin" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>pcost</td>
<td>
<input maxlength="6" name="pcost" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>bcost</td>
<td>
<input maxlength="6" name="bcost" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>laborrate</td>
<td>
<input maxlength="6" name="laborrate" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>hours</td>
<td>
<input maxlength="6" name="hours" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>qtyapps</td>
<td>
<input maxlength="6" name="qtyapps" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>incbaseapp</td>
<td>
<input maxlength="6" name="incbaseapp" value="2" onChange=ValidateJob(); size="6">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>wayapps</td>
<td>
<input type="checkbox" name="wayapps"> <input type="checkbox" name="wayapps">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>wallt</td>
<td>
<input type="checkbox" name="wallt">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>wallht</td>
<td>
<input type="checkbox" name="wallht">
</td>
</tr>
<tr bgcolor="#FFCC33">
<td>verydry</td>
<td>
<input type="checkbox" name="verydry">
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Rate</b></td>
</tr>
<tr>
<td>Regular</td>
<td>
<input CHECKED name="typrate" type="radio" value="12.50">
</td>
</tr>
<tr>
<td>Professional</td>
<td>
<input name="typrate" type="radio" value="17.50">
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Paint</b></td>
</tr>
<tr>
<td>Flat</td>
<td>
<input CHECKED name="qtyapps" type="radio" value="24">
</td>
</tr>
<tr>
<td>Satin</td>
<td>
<input name="qtyapps" type="radio" value="31.50">
</td>
</tr>
<tr >
<td>Gloss</td>
<td>
<input name="incbaseapp" type="radio" value="27.75">
</td>
</tr>
<tr>
<td>Semi Gloss</td>
<td>
<input name="incbaseapp" type="radio" value="27.75">
</td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#B6D4D2">
<input onClick=ValidateJob(); type="button" value="Calculate" name="button">
<input type="submit" value="Clear Values" name="submit"><br>
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Calculated Results</b>
</td>
</tr>
<tr>
<td>Basic Wall Square Footage</td>
<td>
<input maxlength="18" name="wallsqfeetc" size="18">
</td>
</tr>
<tr>
<td>Rounded Application Paintable Square Footage</td>
<td>
<input maxlength="4" name="sqfeet" size="4">
</td>
</tr>
<tr>
<td>Calculated Application Paintable Square Footage</td>
<td>
<input maxlength="18" name="sqfeetc" size="18">
</td>
</tr>
<tr>
<td>Approximate Gallons Of Application Paint To Purchase</td>
<td>
<input maxlength="6" name="paintgals" size="6">
</td>
</tr>
<tr>
<td>Calculated Gallons Of Application Paint Required</td>
<td>
<input maxlength="18" name="paintgalsc" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of Application Paint Required</td>
<td>
$<input maxlength="18" name="pexpense" size="18">
</td>
</tr>
<tr bgcolor="#FFCC00">
<td>paintbgalsc</td>
<td>
$<input maxlength="18" name="paintbgalsc" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of All Paint Required</td>
<td>
$<input maxlength="18" name="paintexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of Labor Required</td>
<td>
$<input maxlength="18" name="laborexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Total Expense Of This Wall Or Walls</td>
<td>
$<input maxlength="18" name="allexpense" size="18">
</td>
</tr>
</form>
</body>
</html>
#6
Posted 18 January 2011 - 04:00 PM
okay here is the updated code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module 2</title>
</head>
<body>
<?php
$widths = array(0 => 20,30,20,40,50,30,50,30);
$heights = array(0 =>9,9,9,9,10,10,10,10);
$rates = array('PROFESSIONAL'=>17.50,'REGULAR'=>12.50);
$types = array('FLAT'=>24.00,'SATIN'=>31.50,'GLOSS'=>27.75);
DEFINE('COVERAGE',310);
DEFINE('TIME',8);
$index=0;
$totalTime=0;
$totalGal = 0;
?>
<SCRIPT Language="JavaScript">
<!--
var acover = 310; // application paint coverage per gallon of paint in square feet
var afeet = 0; // actual square footage of wall
var laborratereg = 0; //
var paint = 0; //
var laborratepro = 0; //
var hours = 0; //
var length = 0; //
var width = 0; //
var recalc = 0; //
function calcRound(num, precision) {
var precision = 2; //default value if not passed from caller, change if desired
// remark if passed from caller
precision = parseInt(precision); // make certain the decimal precision is an integer
var result1 = num * Math.pow(10, precision);
var result2 = Math.round(result1);
var result3 = result2 / Math.pow(10, precision);
return zerosPad(result3, precision);
}
function zerosPad(rndVal, decPlaces) {
var valStrg = rndVal.toString(); // Convert the number to a string
var decLoc = valStrg.indexOf("."); // Locate the decimal point
// check for a decimal
if (decLoc == -1) {
decPartLen = 0; // If no decimal, then all decimal places will be padded with 0s
// If decPlaces is greater than zero, add a decimal point
valStrg += decPlaces > 0 ? "." : "";
}
else {
decPartLen = valStrg.length - decLoc - 1; // If there is a decimal already, only the needed decimal places will be padded with 0s
}
var totalPad = decPlaces - decPartLen; // Calculate the number of decimal places that need to be padded with 0s
if (totalPad > 0) {
// Pad the string with 0s
for (var cntrVal = 1; cntrVal <= totalPad; cntrVal++)
valStrg += "0";
}
return valStrg;
}
// send the value in as "num" in a variable
// clears field of default value
function clear_field(field) {
if (field.value==field.defaultValue) {
field.value=''
}
}
// make sure it is a number or a decimal
function ValidateNumber(rVal)
{
inLen = rVal.length;
for(var i=0; i<inLen; i++) {
var ch = rVal.substring(i,i+1);
if (! (ch> "0" || "9"> ch || ch == ".") )
{
alert("Entry incorrect, please re-enter");
return -1;
}
}
return rVal;
}
function ValidateJob()
{
ExecuteJob();
if (gallonsc > gallons) {
gallons = Math.round(gallons) + 1;
} // make sure you buy enough application paint!!!!
else {
gallons = Math.round(gallons);
}
document.PaintForm.wallsqfeetc.value = afeet; // basic wall square feet
document.PaintForm.sqfeet.value = feet; // rounded paintable square feet after options applications
document.PaintForm.paintgals.value = gallons; // purchase quantity application
document.PaintForm.paintgalsc.value = gallonsc;
document.PaintForm.pexpense.value = calcRound(gallons * pexpense);
document.PaintForm.laborexpense.value = calcRound(cost * time);
document.PaintForm.paintexpense.value = calcRound((gallons * pexpense));
document.PaintForm.allexpense.value = calcRound((gallons * pexpense) + (cost * time));
}
function ExecuteJob()
{
var length = ValidateNumber(document.PaintForm.length.value);
if (length == -1) {
document.PaintForm.length.value = 0;
length = 0;
}
var height = ValidateNumber(document.PaintForm.height.value);
if (height == -1) {
document.PaintForm.height.value = 0;
height = 0;
}
var acover = ValidateNumber(document.PaintForm.acover.value);
if (acover == -1) {
document.PaintForm.acover.value = 0;
acover = 0;
}
afeet = (height * length); // actual square footage of wall - no ceiling
}
pfeet = (afeet); // actual paintable square feet - no adjustments for texture or coats
var pcost = ValidateNumber(document.PaintForm.pcost.value); // decimal
if (pcost == -1) { // -1 means invalid input
document.PaintForm.pcost.value = 0;
pcost = 0; // cost per gallon of application paint
}
var laborrate = ValidateNumber(document.PaintForm.laborrate.value); // decimal
if (laborrate == -1) { // -1 means invalid input
document.PaintForm.laborrate.value = 0;
laborrate = 0; // cost per hour to paint
}
var hours = ValidateNumber(document.PaintForm.hours.value); // decimal
if (hours == -1) { // -1 means invalid input
document.PaintForm.hours.value = 0;
hours = 0; // estimated hours to paint
}
calcRound (laborrate); //format money to 2 decimal places
cost = laborrate; // base coat no or yes, default is no
calcRound (hours); //format to 2 decimal places
time = hours; // base coat no or yes, default is no
calcRound (pcost); //format money to 2 decimal places
pexpense = pcost; // application coats 1 or 2, default is 1
if (document.PaintForm.qtyapps[1].checked)
{
qtyapps = 2;
}
else
{
qtyapps = 1;
}
// -->
</SCRIPT>
</HEAD>
<NOSCRIPT>
This document requires JavaScript enabled browsers; verify that yours is capable and perhaps only turned off.
</NOSCRIPT>
<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>
<h1><center>Module 2</center></h1>
<td>
<TABLE ALIGN="center" BORDER=5 CELLPADDING=5>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Wall Design</b>
</td>
</tr>
<tr>
<!--ROW 1-->
<tr>
<td>Wall Length</td>
<td>
<input maxlength="6" name="length" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<tr>
<td>Wall Width</td>
<td>
<input maxlength="6" name="width" value="10" onChange=ValidateJob(); size="6">
Feet</td>
</tr>
<TR bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Anticipated Paint Coverage</b></td>
<tr>
<td>Application Coat Coverage Square Feet</td>
<td>
<input maxlength="6" name="acover" value="310" onChange=ValidateJob(); size="6"> Per Gallon
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Rate</b></td>
</tr>
<tr>
<td>Regular</td>
<td>
<input CHECKED name="typrate" type="radio" value="12.50">
</td>
</tr>
<tr>
<td>Professional</td>
<td>
<input name="typrate" type="radio" value="17.50">
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Type of Paint</b></td>
</tr>
<tr>
<td>Flat</td>
<td>
<input CHECKED name="paint" type="radio" value="24">
</td>
</tr>
<tr>
<td>Satin</td>
<td>
<input name="paint" type="radio" value="31.50">
</td>
</tr>
<tr >
<td>Gloss/Semi Gloss</td>
<td>
<input name="paint" type="radio" value="27.75">
</td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#B6D4D2">
<input onClick=ValidateJob(); type="button" value="Calculate" name="button">
<input type="submit" value="Clear Values" name="submit"><br>
</td>
</tr>
<tr bgcolor="#B6D4D2">
<td colspan="2" align="center">
<b>Calculated Results</b>
</td>
</tr>
<tr>
<td>Basic Wall Square Footage</td>
<td>
<input maxlength="18" name="wallsqfeetc" size="18">
</td>
</tr>
<tr>
<td>Calculated Application Paintable Square Footage</td>
<td>
<input maxlength="18" name="sqfeetc" size="18">
</td>
</tr>
<tr>
<td>Calculated Gallons Of Application Paint Required</td>
<td>
<input maxlength="18" name="paintgalsc" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of All Paint Required</td>
<td>
$<input maxlength="18" name="paintexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Expense Of Labor Required</td>
<td>
$<input maxlength="18" name="laborexpense" size="18">
</td>
</tr>
<tr>
<td>Calculated Total Expense Of This Wall Or Walls</td>
<td>
$<input maxlength="18" name="allexpense" size="18">
</td>
</tr>
</body>
</html>
#7
Posted 18 January 2011 - 04:50 PM
Well, in the Error console, I'm getting the following when I press "Calculate":
Document.PaintForm is undefined
Are you using FireBug (in Firefox) and the Error Console to help you debug at all?
Document.PaintForm is undefined
Are you using FireBug (in Firefox) and the Error Console to help you debug at all?
#8
Posted 18 January 2011 - 06:14 PM
#9
Posted 19 January 2011 - 01:10 AM
did you ever tried the code which i posted at my above post?
it calculates it fine!
it calculates it fine!
#10
Posted 19 January 2011 - 08:22 AM
#11
Posted 19 January 2011 - 08:24 AM
your Calculate function needs to all those fields!
if you don't want to calculate them, then just hide those field. but dont delete them, because ur calculate function still looking for them.
i mean you can replace them with HIDDEN INPUTS
ex:
btw i did not added any avascript code to it.
all i did was adding missed HTML inputs, not more!
if you don't want to calculate them, then just hide those field. but dont delete them, because ur calculate function still looking for them.
i mean you can replace them with HIDDEN INPUTS
ex:
<input type="hidden" name="length" value="1" />
btw i did not added any avascript code to it.
all i did was adding missed HTML inputs, not more!
#12
Posted 19 January 2011 - 08:49 AM
Ok thanks..I am a newb when it comes to JS. Thanks for your help
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









