I am new at JavaScript. I have created an asp that our customers will use to obtain an estimate for a service we perform. Data they enter into the form will be submitted to us through email - that part works fine.
The form contains several fields where the user will indicate the number of pieces of equipment that they have requiring service. When the user clicks a button, I need the form to calculate the following: Estimated Cost = (NumberEquipment1 * CostPerEquipment1) + (NumberEquipment2 * CostPerEquipment2), etc......for each equipment type. Once calculated, the result should display on the form.
I'm stuck on that as well as how to make the Estimated Cost appear to the right of the label.
I found minimal help on another forum, and attempted to modify my code, but I really don't know what I'm doing (obviously). If someone could take a look at this sample script and point me in the right direction, I'd be most grateful.
Thanks...cs
<SCRIPT LANGUAGE = "JavaScript" type="text/javascript">
aCostPerEquip = new Array("MachRooms",100, "Compressors", 200);
function GetEstimate(oForm) {
for (var n = 0; n < aCostPerEquip.length; n += 2) {
var oInput = document.form1.MachRooms
var oInput = document.form1.Compressors
if (sVarMachRooms = "MachRooms"
if (sVarCompressors = "Compressors"
var iNumMachRooms = parseInt(oInput.value);
var iNumCompressors = parseInt(oInput.value);
var iTotalCost = (iNumMachRooms*aCostPerEquip[n+1])+ (iNumCompressors*aCostPerEquip[n+1])
}
function Validate()
{
{
f = document.form1
}
f.submit();
}
}
</script>
</HEAD>
<BODY>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=1>
<TR>
<form action=" method="post" onSubmit="Validate();" id="form1" name="form1">
<input type="hidden" name="fcount" value="2"><input type="hidden" name="thanksurl" value=" type="hidden" name="recipient" value="cs@OurCompany.com">
<TR>
<td colspan="4"><b>Please enter the number of:</b></td>
</tr>
<TR>
<td>Machine Rooms:</td>
<td colspan="3"><input type="text" name="MachRooms" class="bodycopy" size="2" >
<input type="hidden" name="1f" value="MachRooms"></td>
</TD>
<TR>
<TD>Compressors:</TD>
<TD colspan="3"><input type="text" name="Compressors" class="bodycopy" size="2">
<input type="hidden" name="2f" value="Compressors">
</td>
</TR>
<TR>
<TD><B>Estimated Cost:</B></td>
<td><input type="text" value = "" name="TotalCost" size="50"> </TD>
</TD>
<TR>
<TD><INPUT TYPE="button" value="Calculate Estimate" On_Click="TotalCost.value=(iTotalCost)" name="button">
<TD><INPUT TYPE="Submit" name = "Submit" value="Request Written Proposal" >
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
The form contains several fields where the user will indicate the number of pieces of equipment that they have requiring service. When the user clicks a button, I need the form to calculate the following: Estimated Cost = (NumberEquipment1 * CostPerEquipment1) + (NumberEquipment2 * CostPerEquipment2), etc......for each equipment type. Once calculated, the result should display on the form.
I'm stuck on that as well as how to make the Estimated Cost appear to the right of the label.
I found minimal help on another forum, and attempted to modify my code, but I really don't know what I'm doing (obviously). If someone could take a look at this sample script and point me in the right direction, I'd be most grateful.
Thanks...cs
<SCRIPT LANGUAGE = "JavaScript" type="text/javascript">
aCostPerEquip = new Array("MachRooms",100, "Compressors", 200);
function GetEstimate(oForm) {
for (var n = 0; n < aCostPerEquip.length; n += 2) {
var oInput = document.form1.MachRooms
var oInput = document.form1.Compressors
if (sVarMachRooms = "MachRooms"
if (sVarCompressors = "Compressors"
var iNumMachRooms = parseInt(oInput.value);
var iNumCompressors = parseInt(oInput.value);
var iTotalCost = (iNumMachRooms*aCostPerEquip[n+1])+ (iNumCompressors*aCostPerEquip[n+1])
}
function Validate()
{
{
f = document.form1
}
f.submit();
}
}
</script>
</HEAD>
<BODY>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=1>
<TR>
<form action=" method="post" onSubmit="Validate();" id="form1" name="form1">
<input type="hidden" name="fcount" value="2"><input type="hidden" name="thanksurl" value=" type="hidden" name="recipient" value="cs@OurCompany.com">
<TR>
<td colspan="4"><b>Please enter the number of:</b></td>
</tr>
<TR>
<td>Machine Rooms:</td>
<td colspan="3"><input type="text" name="MachRooms" class="bodycopy" size="2" >
<input type="hidden" name="1f" value="MachRooms"></td>
</TD>
<TR>
<TD>Compressors:</TD>
<TD colspan="3"><input type="text" name="Compressors" class="bodycopy" size="2">
<input type="hidden" name="2f" value="Compressors">
</td>
</TR>
<TR>
<TD><B>Estimated Cost:</B></td>
<td><input type="text" value = "" name="TotalCost" size="50"> </TD>
</TD>
<TR>
<TD><INPUT TYPE="button" value="Calculate Estimate" On_Click="TotalCost.value=(iTotalCost)" name="button">
<TD><INPUT TYPE="Submit" name = "Submit" value="Request Written Proposal" >
</td>
</tr>
</table>
</form>
</BODY>
</HTML>