繁体   English   中英

两个提交按钮具有相同的操作,而其中一个具有添加的功能/操作,用于相同的表单

[英]Two submit buttons with same action and one from them with added function/action for the same form

我有一个带有两个submit按钮的form

<form id="manageSalesForm" name="manageSalesForm" method="post" action="<?php echo BASE_URL?>includes/functions/sales_functions.php">

PROCEED按钮应将数据提交到数据库 (有效)

<input type="submit" name="btnProceed" id="btnProceed" value="PROCEED" onclick="document.getElementById('txtSubTotal').value = '';"/>

PRINT & PROCEED按钮应将数据提交到数据库并打印页面 (如何执行此操作?)

<input type="submit" name="btnPrintReceipt" id="btnPrintReceipt" value="PRINT &amp; PROCEED" formaction="<?php echo BASE_URL?>reports/salesreceipt2.php" formtarget="_blank"/>

salesreceipt2.phpfpdf代码,并要在新标签/窗口中打开此。

同一表单具有另一个button类型的button

<button type="button" name="btnSave" id="btnSave" onclick="submitdata(); resetform();">ADD</button>

function submitdata() {
              var listItemName  = document.getElementById("listItemName").value;
              var listStock = document.getElementById("listStock").value;
              var txtUnitPrice = document.getElementById("txtUnitPrice").value;
              var txtQuantity = document.getElementById("txtQuantity").value;
              var listCustomer = document.getElementById("listCustomer").value;
              var txtReceiptNo = document.getElementById("txtReceiptNo").value;
              var TheDate = document.getElementById("TheDate").value;

              // Returns successful data submission message when the entered information is stored in database.
              var dataString = {listItemName:listItemName, listStock: listStock, txtUnitPrice: txtUnitPrice, txtQuantity: txtQuantity, listCustomer: listCustomer, txtReceiptNo: txtReceiptNo};
              if (listItemName == '' || listStock == ''|| txtUnitPrice == ''|| txtQuantity == ''|| listCustomer == ''|| txtReceiptNo == ''|| TheDate == '') {
              salesitemsAddFail();
              } 
              else {
                         // AJAX code to submit form.
                         $.ajax({
                         type: "POST",
                         url: "/pms/includes/functions/sales_temp_functions.php",
                         data: dataString,
                         cache: false,
                         success: function(html) {    

              //reload the sales datagrid once add the item details to temporary table (sales_temp)
              $('#list').trigger("reloadGrid",[{page:1}]);
                 //window.location.reload();
                 //refresh/update the sub total value when adding
                 $("#sub_total_div").load(location.href + " #sub_total_div");

                         }
                         });
                     }
         }

我尝试了几种方法,但无法完成这项工作。 感谢您的帮助。

首先将所有提交更改为按钮。 像这样 :

<input type="button" value="Proceed" onclick="proceed(false)" />
<input type="button" value="Proceed & Print" onclick="proceed(true)" />

现在添加以下JavaScript:

function print(recordId){
    window.open( 'baseurl/salesreceipt2.php?id='+recordId , '_blank');
}
function proceed(printIt){
    // your ajax operations..
    $.ajax({
        //your ajax configs..
        success:function(response){
            //your ajax success things..
            if(printIt == true){
                print(response.lastId); // Pass last Id of record to print function if your salesreceipt2.php always prints last record that's unnecessary.
            }
        }
    });
}

它很容易。 如果printIt(您的第一个参数)为true,则使用LastRecordId调用print(如果您的salesreceipt2.php始终打印通过的最后一条记录是不必要的,如我所说。)如果不是,则应返回包含插入ID的JSON响应。 因此,此插入的ID将由?id传递到salesreceipt2.php文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM