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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am new at JavaScript. I have crea

Status
Not open for further replies.

Fris

Programmer
Jun 23, 2003
22
US
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 = &quot;JavaScript&quot; type=&quot;text/javascript&quot;>

aCostPerEquip = new Array(&quot;MachRooms&quot;,100, &quot;Compressors&quot;, 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 = &quot;MachRooms&quot;)
if (sVarCompressors = &quot;Compressors&quot;)

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=&quot;100%&quot; border=1>

<TR>
<form action=&quot; method=&quot;post&quot; onSubmit=&quot;Validate();&quot; id=&quot;form1&quot; name=&quot;form1&quot;>
<input type=&quot;hidden&quot; name=&quot;fcount&quot; value=&quot;2&quot;><input type=&quot;hidden&quot; name=&quot;thanksurl&quot; value=&quot; type=&quot;hidden&quot; name=&quot;recipient&quot; value=&quot;cs@OurCompany.com&quot;>
<TR>
<td colspan=&quot;4&quot;><b>Please enter the number of:</b></td>
</tr>

<TR>
<td>Machine Rooms:</td>
<td colspan=&quot;3&quot;><input type=&quot;text&quot; name=&quot;MachRooms&quot; class=&quot;bodycopy&quot; size=&quot;2&quot; >
<input type=&quot;hidden&quot; name=&quot;1f&quot; value=&quot;MachRooms&quot;></td>
</TD>
<TR>
<TD>Compressors:</TD>
<TD colspan=&quot;3&quot;><input type=&quot;text&quot; name=&quot;Compressors&quot; class=&quot;bodycopy&quot; size=&quot;2&quot;>
<input type=&quot;hidden&quot; name=&quot;2f&quot; value=&quot;Compressors&quot;>
</td>
</TR>

<TR>
<TD><B>Estimated Cost:</B></td>
<td><input type=&quot;text&quot; value = &quot;&quot; name=&quot;TotalCost&quot; size=&quot;50&quot;> </TD>

</TD>
<TR>
<TD><INPUT TYPE=&quot;button&quot; value=&quot;Calculate Estimate&quot; On_Click=&quot;TotalCost.value=(iTotalCost)&quot; name=&quot;button&quot;>
<TD><INPUT TYPE=&quot;Submit&quot; name = &quot;Submit&quot; value=&quot;Request Written Proposal&quot; >

</td>
</tr>
</table>
</form>
</BODY>
</HTML>
 
to the right of what label? i see u have a textbox for it. do u want it to appear in the textbox?
then try this:
document.FormName.TextboxName.value=&quot;SomeValue&quot;

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top