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

How to calculate a form total

Status
Not open for further replies.

liamm

Technical User
Aug 12, 2002
102
GB
Hi, can anyone help me with a script. I want someone to be able to select options from dropdwon boxes and be able to press a button to calculate the total. If they wish they can then submit the form to a script which will mail the contents to me. I have the mail script but I cannot do the javascript to calculate the form total. Thanks for the help. If you can help, GREAT
If I can help, EVEN BETTER
 
Hi
You haven't said what calculations you want to do and what you want to do with the result but this should give you an idea of what to do.
Your selects and button will look something like this within your form.
Code:
<select id=&quot;select1&quot;>
<option value=1>1
<option value=2>2
<option value=3>3
</select>

<select id=&quot;select2&quot;>
<option value=1>1
<option value=2>2
<option value=3>3
</select>

<input type=&quot;button&quot; value=&quot;Calculate&quot; onClick=&quot;CalculateIt(select1.value,select2.value)&quot;>

and then you would have this script in the head section of your page. This just adds the numbers together.
Code:
<script>
function CalculateIt(num1, num2){
  num1=parseInt(num1);
  num2=parseInt(num2);
  total=num1+num2;
  alert(total);
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top