Mutiplication
Moderator: General Moderators
Mutiplication
Iam tring to calculate a result between two fields how can this be done in HTML or yet alone PHP
HTML is layout-only and can't do math. I suppose you're using a form and both values of the form-fields are integers. Once submitted, the values of the form-fields will be usable by PHP:
Code: Select all
<?php
$result=$_POST["formfield1"]*$_POST["formfield2"];
echo "Result: $result";
?>
Last edited by patrikG on Thu Mar 06, 2003 2:38 pm, edited 1 time in total.
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
If you have a form with fields named "number1" and "number2"
Clientside, use javascript:
Server-side, pass the vars in a form, and just do simple multiplication with PHP (similar to the JA stuff)
Clientside, use javascript:
Code: Select all
<HTML>
<HEAD>
<script language="javascript">
function Multiply_Them(){
var number1=document.myform.number1.value;
var number2=document.myform.number2.value;
var product=number1*number2;
document.myform.product.value=product;
}
</script>
</HEAD>
<BODY>
<form name="myform">
<input type="text" name="number1">
<input type="text" name="number2">
<input type="text" name="product">
<input type="button" onclick="Multiply_Them">
</form>
</BODY>
</HTML>