0

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>
3
  • Maybe you want to print the return value of the function with echo ? Just a idea... Commented Feb 26, 2015 at 19:52
  • 1
    All this talk about food has given me the munchies. Commented Feb 26, 2015 at 20:03
  • <?= subTotal($incomingQuantity , $incomingPrice ) ?> simple as adding an equal sign; assuming short tags are set/on. ;-) Commented Feb 26, 2015 at 20:14

2 Answers 2

3

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
}
Sign up to request clarification or add additional context in comments.

2 Comments

and to be safe with the compiler, add a semicolon after each command.
Could've just added an = - <?= subTotal($incomingQuantity , $incomingPrice ) ?> - Well, assuming short tags are set ;-)
0

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.