Hello, I'm working on instant quote order form, the user choose items through radio buttons and options menu.. and instant calculations of items prices are viewed under the form, I built the form using HTML, processed Validation and Items Prices through Javascript.. recently i succeded to build the form/ Culcolator/ and used PHP FILE to process data entered to client Email & My email to get the order.. But The problem is that i cant get the total price within the email message, or even within the php file to use it as the total amount to be paid via 2checkout.. Please Help to Make it Javascript Calculating Function function calculateTotal(){ //Here we get the total price by calling our function //Each function returns a number so by calling them we add the values they return together var cakePrice = getCakeSizePrice() + getFillingPrice() + candlesPrice() + insciptionPrice(); //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For the Cake $"+cakePrice; } function hideTotal() { var divobj = document.getElementById('totalPrice'); divobj.style.display='none'; } Code (markup): Price Displaying in HTML Form : <div id="totalPrice" value="totalPrice" name="totalPrice" ></div> Code (markup): PHP File <?php$name = $_POST['name']; $email = $_POST['email']; $phonenumber = $_POST['phonenumber']; $additionalnotes = $_POST['additionalnotes']; $selectedcake = $_POST['selectedcake']; $includecandles = $_POST['includecandles']; $includecandles2 = $_POST['includecandles2']; $includecandles3 = $_POST['includecandles3']; $includecandles4 = $_POST['includecandles4']; $filling = $_POST['filling']; $totalPrice = $_GET['<script>{ var cakePrice }</script>']; $includeinscription = $_POST['includeinscription']; $formcontent=" From: $name \n Email: $email \n Phone: $phonenumber \n Additional Notes: $additionalnotes \n \n Order Items: \n $selectedcake \n $includecandles \n $includecandles2 \n $includecandles3 \n $includecandles4 \n Webstie Design: $filling \n Total Price: $totalPrice"; $recipient = "webdev.3738life@yahoo.com, $email"; $subject = "NEW ORDER"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); //Thank You Page.. echo "Your Order information was sent."; echo "Thanks for ordering with us."; echo $totalPrice; Code (markup): so how can i get the total price in the php file, so i can use it to be sent on my email and to be used within 2checkout code to process payment ?? Please Help, Thanks
Javascript resides on the client side. You cannot pass the value of a Javascript variable to the server as you're trying to do... A simple alternative would be to add an hidden input field to your form and change its value through javascript. Something like this: <form action="order.php" method="POST"> **Your form goes here** <input type="hidden" id="price" name="price" value="" /> </form> Code (markup): Then just modify your calculateTotal function: function calculateTotal(){ //Here we get the total price by calling our function //Each function returns a number so by calling them we add the values they return together var cakePrice = getCakeSizePrice() + getFillingPrice() + candlesPrice() + insciptionPrice(); //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For the Cake $"+cakePrice; document.getElementById('price').value = cakePrice; } Code (markup): And the value will be sent with your form: $price = $_POST['price']; PHP:
Thank you very much, it really worked,, Thanks again.. but i do have another problem now, that sometimes the price reach 2checkout exactly as i ordered, some other times i got different price at 2checkout than the price of my order, and another times i got empty cart at 2checkout.. thats the code am using for 2checkout : echo "<form action='https://www.2checkout.com/checkout/purchase' method='post'><input type='hidden' name='sid' value='my-2co-id' > <input type='hidden' name='total' value='$price' > <input type='hidden' name='cart_order_id' value='$selectedcake $includecandles $includecandles2 $includecandles3 $includecandles4 $filling' > <input type='hidden' name='id_type' value='1' > <input type='hidden' name='c_prod' value='PRODUCT-10,1' > <input type='hidden' name='c_name' value='Product 10' > <input type='hidden' name='c_description' value='This is my 10th product' > <input type='hidden' name='c_price' value='88' > <input name='submit' type='submit' value='Buy from 2CO' > </form>"; Code (markup): Any help would be appreciated, Thanks again