...

View Full Version : Multiplying Form Fields



slash75
01-16-2009, 07:35 PM
I am working on the form below.
I want to add together the #'s from the Girls and Adults field then multiply that # by the Hours field and have the total placed in the Total Hours Given field.

Ex.
Girls = 2
Adults = 5
Hours = 10
Total HoursGiven = 20

Then I want to take the Total Hours Given # and add it to the #'s in the Girl Hours and Adult Hours fields and have that # placed in the New Total # of hours given field.

Ex.
Total Hours Given = 20
Girls Hours = 5
Adult Hours = 5
New Total # of hours given = 30

I have started working with the first part but can't get the multiplication to work. I was wondering if someone could take a look and tell me what I am doing wrong.




<html>
<head>

<script type="text/javascript">

//Calulate Total
function startTotal(){
interval = setInterval("calcTotal()",1);
}
function calcTotal(){
var g1girl = document.sog.g1GirlPar1.value;
var g1adult = document.sog.g1AdultPar1.value;
var g1hours = document.sog.g1HoursServed1.value;
document.sog.g1HoursGiven1.value = (g1girl * 1) + (g1adult * 1) * (g1hours * 1);

}
function stopTotal(){
clearInterval(interval);
}


</script>

</head>
<body>





<form name="sog" method="post" action="send.asp" >
<table width="500" border="0" cellpadding="3" cellspacing="0" bgcolor="#000000" class="main">


<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Girls:</td>
<td align="left"><input name="g1GirlPar1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"></td>
</tr>


<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Adults:</td>
<td align="left"><input name="g1AdultPar1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"> </td>
</tr>


<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Hours:</td>
<td align="left"><input name="g1HoursServed1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"> </td>
</tr>

<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Total Hours Given:</td>
<td align="left">

<input name="g1HoursGiven1" type="text" size="5" value="" class="shadowSm"> Girls + Adults x Hours


</td>
</tr>


<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Girl Hours:</td>
<td align="left"><input name="g1GirlHours1" type="text" size="5" value="" class="shadowSm"> </td>
</tr>

<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>Adult Hours:</td>
<td align="left"><input name="g1AdultHours1" type="text" size="5" value="" class="shadowSm"> </td>
</tr>


<tr valign="top" bgcolor="#FFFFFF" class="main">
<td>New Total # of hours given:</td>
<td align="left">
<input name="g1Hours1" type="text" size="5" value="" class="shadowSm"> Total Hours Given + Girl Hours + Adult Hours
</td>
</tr>





<tr valign="top" bgcolor="#FFFFFF" class="main">
<td><input type="submit" value="Submit" class="xml-icon"></td>
<td align="left">&nbsp;</td>
</tr>
</table>

</form>


</body>
</html>

Philip M
01-16-2009, 08:15 PM
document.sog.g1HoursGiven1.value = ((g1girl * 1) + (g1adult * 1)) * (g1hours * 1);



Quizmaster: In Roman Catholicism, baptism, confirmation and matrimony are three of the seven what?
Contestant: Deadly sins.

slash75
01-16-2009, 08:58 PM
Of course that is the one thing I didn't think of! Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum