Reputation: 11
Need some help guys I'm working on a order form using Php, I have the function correct because it works fine when I just echo it out. But I can't figure out how to call the function correctly into my div on my table. I want to be able to display the result of quantity times price. Any help would be greatly appreciated.
<?
/*
print_r($_POST)
*/
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$phone = $_POST["phone"];
$email = $_POST["emailAddress"];
$appleQuantity = $_POST["apple"];
$baconQuantity = $_POST["bacon"];
$breadQuantity = $_POST["bread"];
$cheeseQuantity = $_POST["cheese"];
$eggsQuantity = $_POST["eggs"];
$hamQuantity = $_POST["ham"];
$milkQuantity = $_POST["milk"];
$priceApples = 10;
$priceBacon = 2.5;
$priceBread = 5;
$priceCheese = 5;
$priceEggs = 3.6;
$priceHame = 6;
$priceMilk = 4;
function subTotal($incomingQuantity , $incomingPrice)
{
return $incomingQuantity * $incomingPrice;
}
?>
<div align="center"><? subTotal($incomingQuantity , $incomingPrice ) ?></div>
Upvotes: 0
Views: 54
Reputation: 39
suppose you have to display output in a textbox inside a div as
<input type="text" id="myText" >
then your function can be
function subTotal($incomingQuantity , $incomingPrice)
{
var result = $incomingQuantity * $incomingPrice;
document.getElementById("myText").value = result;
}
Upvotes: 0
Reputation: 360672
Your function doesn't do any output, it's just RETURNING the value. You need an echo in there somewhere.
e.g.
<div><?php echo subTotal(...) ?></div>
or
function subTotal(...) {
echo $result
}
Upvotes: 3