Mutiplication

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
cbompart
Forum Newbie
Posts: 9
Joined: Mon Feb 10, 2003 5:47 pm

Mutiplication

Post by cbompart »

Iam tring to calculate a result between two fields how can this be done in HTML or yet alone PHP
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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";
?>
Last edited by patrikG on Thu Mar 06, 2003 2:38 pm, edited 1 time in total.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post 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)
Post Reply