我有一个网站,我们将提供一些产品供会员购买。请参阅http://jsfiddle.net/TbeQx/
<form action="" name="priceCalc" method="POST">
I Am Paying For :
<select name="product" onchange="price();">
<option value="15">item 1 - $15.00</option>
<option value="35">item 2 - $35.00</option>
<option value="35">item 3 - $35.00</option>
<option value="29.90">item 4 - $29.90</option>
<option value="29.90">item 5 - $29.90</option>
<option value="26.90">item 6 - $26.90</option>
<option value="32.90">item 7 - $32.90</option>
<option value="59.90">item 8 - $59.90</option>
<option value="59.90">item 9 - $59.90</option>
</select>
<br />
<br />
Quantity :
<select name="quantity" onchange="price();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br />
<br />
Please deposit the freight free full total of <br />
<span style="color:red; font-size:18px;" id="prices">$</span>
into our account :
<br />
<input type="submit" name="submit" value="BUY NOW!" />
</form>
/* JavaScript */
function price() {
var qty = document.priceCalc.quantity;
var itm = document.priceCalc.product;
var price = parseInt(qty.value) * parseInt(itm.value);
document.getElementById("prices").innerHTML = '$' + price;
}
如何自动计算价格并将其显示在两个下拉列表的 id="prices" 跨度标签之间。
这向用户显示总数是多少。
然后在提交时,我需要它向指定的电子邮件地址发送一封电子邮件,说..“数量”x“项目名称”=“数量”
(例如,2 x 项目 4 - 29.90 美元 = 59.80 美元)
我的 php 在这里http://jsfiddle.net/8hzNV/
<?php
$quantity = $_POST["quantity"];
$item = $_POST["product"];
$subject = "Website Sale!";
$emailto = "myemail@test.com";
// prepare email body text
$body .= "";
$body .= "To Sales Team";
$body .= "\n";
$body .= "\n";
$body .= "I have purchased ";
$body .= $quantity;
$body .= "x ";
$body .= $item;
$body .= "\n";
$body .= "\n";
$body .= "Please look out for my payment in the account over the next few days.";
// send email
$success = mail($emailto, $subject, $body");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=../order_sent.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=../index.php\">";
}
?>
我自己也尝试过。但这不是我的强项,希望我能寻求一些专家的建议。提前致谢!!