douwei1408 2014-01-22 13:17
浏览 14
已采纳

动态改变形式动作?

I think this question has been asked a few times and I did find a few on google too.

However I am not trying to change the whole form action. I just need to change it partially.

Here is what I mean:

I have the following form:

    <form action="order.php?add=<?php echo $product_name; ?>&amp;price=<?php echo $price; ?>&amp;qty=1" method="post">
        <input type="text" name="qty" id="qty" class="qty"  size="12"   />
        <input type="submit" class="button2" name="buttonadd" id="button" value="Add to cart" />
   </form>

what I need to do is to change the qty=1 in the form action so it reflects the <input type="text" name="qty" id="qty" class="qty" size="12" /> value!

How can I achieve this?

  • 写回答

4条回答 默认 最新

  • dongqiao6445 2014-01-22 13:24
    关注

    Set the Form method to 'get' (the thing that's now POST)

    <form action="order.php" method="get">
        <input type="hidden" name="add" value="<?php echo $product_name ?>" />
        <input type="hidden" name="price" value="<?php echo $price ?>" />
        <input type="text" name="qty" id="qty" class="qty"  size="12"   />
        <input type="submit" class="button2" name="buttonadd" id="button" value="Add to cart" />
    </form>
    

    And there you have it! :)

    (I also removed the other URL parameters and put them into hidden inputs. In my opinion, this is a much cleaner way to do this.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?