Multiple submit button in a form

前端 未结 4 909
挽巷
挽巷 2020-12-21 06:34

Hey I am very new to Web Programming. I have been learning PHP from the past few days and I am stuck at one thing.

I have a form tag in my code which has two submit

4条回答
  •  时光取名叫无心
    2020-12-21 07:25

    One way is to use Javascript to switch the form's action depending on which control has been clicked. The following example uses the jQuery library:

    ...
    ​ $(document).ready(function() { $("#theForm input").click(function(e) { e.preventDefault(); if(e.target.id == 'first') { $("#theForm").attr("action", "somePage.php"); } else { $("#theForm").attr("action", "anotherPage.php"); } alert($("#theForm").attr("action")); $("#theForm").submit(); }); ​});​

    Demo here: http://jsfiddle.net/CMEqC/2/

提交回复
热议问题