du12197 2013-05-03 09:40
浏览 132
已采纳

使用2个按钮从一个表单发送POST数据

How can I send the POST data from my form to two different pages depending on which post button is clicked?

My "Export" button sends the POST data to 'export.php', but the "Graphique" button must send the POST data to the 'graphique.php' page.

Here is my code:

<form name="TCAgregat" class="TCAgregat" action="export.php" method="post">

    <input type="hidden" name="daco" value="<?php echo $DConso; ?>"></input>
    <input type="hidden" name="CNS" value="<?php echo $CNewCentres; ?>"></input>

    <input type=submit border="0" class="EXP" name="exp" value="EXPORT" />  
    <input type=submit border="0" class="DCB" name="dcb" value="GRAPHIQUE" />
</form>

How can I achieve this?

  • 写回答

4条回答 默认 最新

  • douli2063 2013-05-03 09:47
    关注

    Change form action on button click:

    $("form").on("click", ":submit", function(e) {
        $(e.delegateTarget).attr('action', $(this).data('action'));
    });
    

    HTML:

    <input type=submit data-action="export.php" value="EXPORT" />
    <input type=submit data-action="graphics.php" value="GRAPHIQUE" />
    

    http://jsfiddle.net/FAnq9/

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

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件