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

math in forms

Status
Not open for further replies.

darinchenry

Technical User
Joined
May 7, 2002
Messages
1
Location
US
I'm making a form in my web site that requires simple addition and multiplication. How can I apply some kind of math script to certiain input fields in my form.For instance if the product field =$10 and the quantity field=5, if you push a button that i've made called calculate, how can i make it read and post $50 in the total field. Thank you in advance for any help---Darin
 
You'll have to use some client-side scripting, either (reccommended) Javascript or VBScript. As a quick example:

<html>
<head>
<title>Untitled</title>
<script>
function maths(val1, val2) {
frmTest.txtOutput.value = (val1 * val2);
}
</script>
</head>
<body>
<form name=&quot;frmTest&quot;>

Value 1: <input type=&quot;text&quot; name=&quot;txtVal1&quot;><br>
Value 2: <input type=&quot;text&quot; name=&quot;txtVal2&quot;>

<input type=&quot;button&quot; name=&quot;Equals&quot; value=&quot;Equals&quot;
onClick=&quot;maths(frmTest.txtVal1.value, frmTest.txtVal2.value);&quot;><br>

Output: <input type=&quot;text&quot; name=&quot;txtOutput&quot;>

</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top