Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to add 2 another functions to this form 2

Status
Not open for further replies.

idaryl

Technical User
Nov 10, 2001
156
0
0
US
I need some help with this: I'm using this form to calculate the cost of cleaning rooms, however I need the results to not show in an alert window, rather have it display in a field called (total) below the calculate button.... also the client wants three prices ( the total; then another field which is 2x the total; and other field which is 2.5x the total; for 3 price ranges).

Is this possible with what I have already done here - I've gone about as far as my abilities allow.... OR is there a simpler way to do all of this???

--------
<html>
<head>
<title> -- </title>
</head>
<body bgcolor="#FFFFFF" text="#000000" marginwidth="0" marginheight="0" topmargin="20" leftmargin="0">
<table width="525" border="0" cellspacing="1" cellpadding="0" bgcolor="#FF9900" align="center">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1" height="363" align="center" bgcolor="#FFFFFF">
<tr>
<td height="2">
<form name="calculate" method="post" action="">
<table width="100%" border="0" cellspacing="2" cellpadding="4"
height="95">
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of living &amp; or family rooms.</font></b></td>
<td width="14%" align="CENTER" height="2">
<div align="center"><font face="Arial">
<input type="text" name="rooms" size="3"
value="0">
</font> </div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of combination living/dining areas [ count as 2 rooms ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="comboroom" size="3" value="0">
</font></div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of double size bedrooms. [ count as 2 rooms ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="dblbed"
size="3" value="0">
</font></div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of standard size bedrooms.</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="bedrms" size="3"
value="0">
</font></div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of bathrooms. [ Average bathroom 5x10 ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="bathrms" size="3"
value="0">
</font></div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of hallways. [ Average hallway 10-15 ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="hallways" size="3"
value="0">
</font> </div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of stairways. [ 15 stairs per set ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="others" size="3"
value="0">
</font></div>
</td>
</tr>
<tr>
<td width="86%" height="2"><b>&nbsp;<font size="-1" face="Arial">Number
of Closets. [ Average closet 5x10 ]</font></b></td>
<td width="14%" height="2" align="CENTER">
<div align="center"><font face="Arial">
<input type="text" name="closets" size="3" value="0">
</font></div>
</td>
</tr>
</table>
<div align="center"><font color="#0000FF">
<script language="JavaScript">


function calculate(form)

{

rooms = eval(form.rooms.value)
comboroom = eval(form.comboroom.value)
dblbed = eval(form.dblbed.value)
bedrms = eval(form.bedrms.value)
bathrms = eval(form.bathrms.value)
hallways = eval(form.hallways.value)
others = eval(form.others.value)
closets = eval(form.closets.value)
GetPriceOne (form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets)

}

function GetPriceOne(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets)

{

PriceOne = rooms * 30
GetPriceTwo(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceOne)
}

function GetPriceTwo(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceOne)

{

PriceTwo = PriceOne + (comboroom * 60)
GetPriceThree(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceTwo)


}

function GetPriceThree(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceTwo)

{
PriceThree = PriceTwo + (dblbed * 60)
GetPriceFour(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceThree)

}

function GetPriceFour(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceThree)

{

PriceFour = PriceThree + (bedrms * 23)
GetPriceFive(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceFour)

}

function GetPriceFive(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceFour)

{
PriceFive = PriceFour + (bathrms * 10)
GetPriceSix(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceFive)

}

function GetPriceSix(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceFive)

{

PriceSix = PriceFive + (hallways * 15)
GetPriceSeven(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceSix)
}

function GetPriceSeven(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceSix)

{

PriceSeven = PriceSix + (others * 30)
GetPriceEight(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceSeven)
}

function GetPriceEight(form, rooms, comboroom, dblbed, bedrms, bathrms, hallways, others, closets, PriceSeven)

{

total = PriceSeven + (closets * 10)
WriteDocument(total)
}

function RoundTocents(n)

{

cents = n * 100;
cents = Math.round(cents);
strcents = "" + cents;
len = strcents.length;
return strcents.substring(0, len - 2) + "." + strcents.substring(len - 2, len);

}

function WriteDocument(total)

{

alert("The total cost is $" + RoundTocents(total))
}

</script>
</font><font face="Arial">&nbsp;&nbsp;&nbsp;</font>
<input type="button"
value="Calculate Estimate" name="B1" onClick="calculate(this.form)">
<input type="reset" value="Clear" name="B2">
<font color="#0000FF"> </font> </div>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
 
If a field contains nothing, then the value is "-- $N.aN"

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakesperean sonnet.
 
So I should set all my initial values to $N.aN rather than 0 - if this is right, then; its another piece of info i can use indefinately

idaryl
idface.gif
 
no, instead you should have a test in your calculateTotals function to determine if each textbox holds a numerical value. If it doesn't, clear it and cancel, otherwise, calculate the total and continue.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Example:

Code:
var rooms = 0;

var e = f.elements['rooms'];
if (isNaN(e.value)) {
    e.value = '';
    return false;
} else {
    rooms = parseInt(e.value);
}

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
(big laugh from me here - at myself of course!) OK you actually think I know what I'm doing (haha) If I stand on my head and study what you just said it may make some sense to me - haha [do you see the humor here - by all means laugh at/with me]

To quote (sort of) from the Kinks - You really lost me -


idaryl
idface.gif
 
Yeah, sorry.

Your first function would look something like this (I haven't tested it - the new stuff is in blue):

Code:
function calculateTotals(f)
{[blue]
  // if sofa is < 0, not numeric, or blank, set to 0
  var v = f.elements['sofa'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['sofa'].value = 0;

  // if loveseat is < 0, not numeric, or blank, set to 0
  v = f.elements['loveseat'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['loveseat'].value = 0;

  // if swivel is < 0, not numeric, or blank, set to 0
  v = f.elements['swivel'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['swivel'].value = 0;

  // if ottoman is < 0, not numeric, or blank, set to 0
  v = f.elements['ottoman'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['ottoman'].value = 0;

  // if dining_chairs is < 0, not numeric, or blank, set to 0
  v = f.elements['dining_chairs'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['dining_chairs'].value = 0;

  // if dining_chairs_back is < 0, not numeric, or blank, set to 0
  v = f.elements['dining_chairs_back'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['dining_chairs_back'].value = 0;

  // if dining_chairs_back_arms is < 0, not numeric, or blank, set to 0
  v = f.elements['dining_chairs_back_arms'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['dining_chairs_back_arms'].value = 0;

  // if recliners is < 0, not numeric, or blank, set to 0
  v = f.elements['recliners'].value;
  if (v.length == 0 || isNaN(v) || v < 0)
    f.elements['recliners'].value = 0;
[/blue]
  var sofa = parseInt(f.elements['sofa'].value);
  var loveseat = parseInt(f.elements['loveseat'].value);
  var swivel = parseInt(f.elements['swivel'].value);
  var ottoman = parseInt(f.elements['ottoman'].value);
  var dining_chairs = parseInt(f.elements['dining_chairs'].value);
  var dining_chairs_back = parseInt(f.elements['dining_chairs_back'].value);
  var dining_chairs_back_arms = parseInt(f.elements['dining_chairs_back_arms'].value);
  var recliners = parseInt(f.elements['recliners'].value);
  var total = 0;
  total += sofa * 105;
  total += loveseat * 75;
  total += swivel * 40;
  total += ottoman * 30;
  total += dining_chairs * 7;
  total += dining_chairs_back * 12;
  total += dining_chairs_back_arms * 20;
  total += recliners * 55;
  writeTotal(total, f);
}

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top