Page 1 of 1

Mutiplication

Posted: Thu Mar 06, 2003 2:21 pm
by cbompart
Iam tring to calculate a result between two fields how can this be done in HTML or yet alone PHP

Posted: Thu Mar 06, 2003 2:37 pm
by patrikG
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";
?>

Posted: Thu Mar 06, 2003 2:38 pm
by daven
If you have a form with fields named "number1" and "number2"

Clientside, use javascript:

Code: Select all

<HTML>
<HEAD>
<script language="javascript">
function Multiply_Them()&#123;
  var number1=document.myform.number1.value;
  var number2=document.myform.number2.value;
  var product=number1*number2;
  document.myform.product.value=product;
&#125;
</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>
Server-side, pass the vars in a form, and just do simple multiplication with PHP (similar to the JA stuff)