我已經在使用javascript的電子商務網站內創建了動態定價表單,並且它工作正常。不過,我寧願將更復雜的定價計算放在HTML表單外部的PHP文件中。 計算相當複雜,我已經得到他們所有使用PHP的工作,但我是新來的PHP和我的生活無法弄清楚如何獲得計算結果返回到HTML表單。然後,用戶可以 「加入購物車」外部php表單結果
這裏是非常簡單的例子,試圖說明
HTML表單
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demoform</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="myform.php">
<label>Width<input type="text" name="width" id="width" size="6"></label><p>
<label>Length<input type="text" name="length" id="length" size="6" ></label><p>
<label>Price $</label> <input id="Price" readOnly size=6 name=Price><p>
<label for=otherprice></label><input id="otherprice" readOnly size=6 type=hidden
name=otherprice><p>
<input type="submit" name="submit" id="submit" value="Get Price" ><p>
<input id="addtocart" title="Add to Cart" onclick="return validate(this.form)" value="Add to Cart" type="submit" ?>
</form>
</body>
</html>
PHP文件
<?php
$width=$_POST['width'];
$length=$_POST['length'];
$Area = $width*$length;
$total = $Area * .01;
$price = round($total * 100)/100;
$otherprice = round($price * 1.2 * 100)/100 ;
?>
<?php echo "$price"?><br/>
<?php echo "$otherprice"?>
它可能不是一個新的頁面打開樂 爲$價格要輸入到HTML價格字段 和$ otherprice是demoform.html頁面
約翰
如果我沒有誤解你,你可以使用ajax與外部的php文件進行通信。只需在Google上搜索jquery ajax。 – SimplyZ 2011-06-05 17:12:11