我有一个带有2个按钮的表单,它们具有来自产品ID的相同动态值 我想要的是当你点击它发送到cart.php的购物车按钮,当你点击它发送到wish.php的愿望按钮
但现在当我点击购物车按钮时,它会发送到cart.php 和 wish.php,反之亦然。
有没有这样的形式,会做我想做的事情?
<form id="form1" name="form1" method="post" >
<input type="hidden" name="pid" value="<?php echo $id; ?>" />
<input type="hidden" name="pidwish" value="<?php echo $id; ?>" />
<input type="SUBMIT" name="submit" class="classname" VALUE="add to cart" onClick="this.form.action='cart.php';this.form.submit()">
<input type="SUBMIT" name="submit" class="classname" VALUE="wishlist" onClick="this.form.action='memberSystem/wishes.php';this.form.submit()">
</form>
答案 0 :(得分:0)
看到你所经过的一切都是固定的隐藏价值,这是错误的:
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" value="<?php echo $id; ?>" />
<input type="SUBMIT" name="submit" class="classname" VALUE="add to cart">
</form>
<form id="form2" name="form1" method="post" action="memberSystem/wishes.php">
<input type="hidden" name="pidwish" value="<?php echo $id; ?>" />
<input type="SUBMIT" name="submit" class="classname" VALUE="wishlist">
</form>
答案 1 :(得分:0)
请尝试它会起作用
<强> JavaScript的:强>
function submitForm(actionPath)
{
document.form1.action =actionPath;
document.form1.submit();
}
HTML:
<form id="form1" name="form1" method="post" >
<input type="hidden" name="pid" value="<?php echo $id; ?>" />
<input type="hidden" name="pidwish" value="<?php echo $id; ?>" />
<input type="SUBMIT" name="submit" class="classname" VALUE="add to cart" onClick="submitForm('cart.php')">
<input type="SUBMIT" name="submit" class="classname" VALUE="wishlist" onClick="submitForm('memberSystem/wishes.php')">
</form>
答案 2 :(得分:0)
请试试这个:
<form id="form1" name="form1" method="post" >
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input type="hidden" name="pidwish" id="pid_wish" value="<?php echo $id; ?>" />
<input type="button" name="submit" class="classname" VALUE="add to cart" onClick="SubmitIt(1);">
<input type="button" name="submit" class="classname" VALUE="wishlist" onClick="SubmitIt(2);">
</form>
并使用Jquery进行表单提交。
<script>
function SubmitIt(checkVal)
{
var pid = $("#pid").value;
var pid_wish = $("#pid_wish").value;
if(checkVal == 1)
{
//submit your form for add cart
}
else
{
//submit your form for wish
}
}
</script>