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



我有一个form,带有两个submit按钮。

<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.php 具有fpdf代码,应在新的选项卡/窗口中打开此。

同一表格具有另一个带有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将通过?

相关内容

  • 没有找到相关文章

最新更新