Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交表单并使用href标签在弹出窗口中打开它_Javascript_Php_Html_Forms - Fatal编程技术网

Javascript 提交表单并使用href标签在弹出窗口中打开它

Javascript 提交表单并使用href标签在弹出窗口中打开它,javascript,php,html,forms,Javascript,Php,Html,Forms,我想使用href标签提交表单,并将提交的表单加载到弹出窗口中 <form method='post' action='" . $paymentURL . "' id='frmPaymentDtl' onsubmit='target_popup(this)'> <a id=\"submit_full_payment\" onclick=\"target_popup(get_form(this).submit())\">Make Full Payment</a>

我想使用href标签提交表单,并将提交的表单加载到弹出窗口中

<form method='post' action='" . $paymentURL . "' id='frmPaymentDtl' onsubmit='target_popup(this)'>
  <a id=\"submit_full_payment\" onclick=\"target_popup(get_form(this).submit())\">Make Full Payment</a>
  <input type='hidden' name='customer_id' value='" . $customer_id . "'/>
  <input type='hidden' name='account_id' value='" . $account_id . "'/>
  <input type='hidden' name='invoice_number' value='" . $invoice_model[0]->number . "'/>
  <input type='hidden' name='detail_id' value='" . $bean->id . "'/>
  <input type='hidden' name='header_id' value='" . $_GET['record'] . "'/>
  <input type='hidden' name='detail_number' value='" . $bean->detail_id . "'/>
  <input type='hidden' name='amount' value='" . number_format($bean->amount,2) . "'/>
  <input type='hidden' name='description' value='" . $paymentSchedule->description . "'/>
  <input type='hidden' name='invoice_id' value='" . $invoice_model[0]->id . "'/>
  <input type='submit' name='submit_btn' class=\"listViewTdToolsS1\" value='Submit Bank/Credit Payment'/>
</form>
<script type='text/javascript'>
  function get_form( element )
  {
    while( element )
    {
      element = element.parentNode
      if( element.tagName.toLowerCase() == \"form\" )
      {
      //alert( element ) //debug/test
        return element
      }
    }
  return 0; //error: no form found in ancestors
  }

  function target_popup(form) {
    window.open('', 'formpopup', 'width=800,height=600,resizeable,scrollbars');
    form.target = 'formpopup';
  }
</script>

付清
函数get_form(元素)
{
while(元素)
{
element=element.parentNode
if(element.tagName.toLowerCase()=“form\”)
{
//警报(元素)//调试/测试
返回元素
}
}
返回0;//错误:在祖先中找不到表单
}
功能目标弹出窗口(表格){
打开(“”,'formpopup','width=800,height=600,可调整大小,滚动条');
form.target='formpopup';
}

这里发生的事情是,当我希望在弹出页面中加载表单时,会显示弹出窗口,但表单会加载到主页面上。此外,我只能使用此处的链接访问表单,因为不允许使用提交按钮。

您需要使用Ajax。以下是您需要执行的操作列表:

  • 停止表单的提交事件(您可以使用
    e.preventDefault();
  • 使用ajax发送数据,然后
  • 做任何你想让ajax成功或出错的回调

    如果您需要任何进一步的帮助,请告诉我:)

    这是我之前的回答,我得到了一个答案,所以让我解释一下

    1-)您不需要使用
    window.open()
    弹出页面。您可以简单地创建一个模态(这是一个引导元素:)并在模态中显示您想要的任何内容。在你的情况下,如果我正确理解你的问题,它将再次成为你的表单元素

    2-)如果要在提交时停止重新加载页面,请使用以下命令:

    $('#frmPaymentDtl').submit(function(e)
      {
          e.preventDefault();
          //Take form's all data with this
          var data = $('#frmPaymentDtl').serialize();
          //Or you can assign all id's to a new variable if you'd like that way.
          //After this open your modal which you have a form inside that.
          //then write all data into input's from "data" variable.
      });
    
    我知道这是一个有点不同,但我知道这将为你工作以及

    还有一件事。如果要将此“数据”变量发送到另一个页面,则需要使用Ajax

    如果您不知道如何检查此项:


    顺便说一句,如果您想使用我的方式,请删除表单的onclick事件。:)

    提交详细信息并获得结果的Ajax代码:

    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    $('#submit_full_payment').click(function () {
        var url = 'YOUR_URL';
        $.ajax({
            type: 'POST',
            url: url,//url to post data
            data: "customer_id=" + $('name=customer_id').val() + "&account_id=" + $('name=account_id').val(),//add other form fields here
            success: function (data) {//process data here
                alert(data);
            },
            error: function (data) {
            alert(data);
            }
        });
    });
    
    
    $(“#提交(全额)付款”)。单击(函数(){
    var url='你的url';
    $.ajax({
    键入:“POST”,
    url:url,//发布数据的url
    数据:“customer\u id=“+$('name=customer\u id').val()+”&account\u id=“+$('name=account\u id').val(),//在此处添加其他表单字段
    成功:函数(数据){//此处处理数据
    警报(数据);
    },
    错误:函数(数据){
    警报(数据);
    }
    });
    });
    

    步骤2:使用对话框显示表单和链接。请参阅这将在主页上隐藏表单,并使用上面给出的ajax处理表单并仅保留在弹出窗口中。如果您不想停留在弹出窗口中,可以忽略以上步骤

    您正在提交表单,然后将调用
    submit()
    的返回值传递给
    target\u popup()

    您需要先调用
    target\u popup()
    并将表单传递给它,然后您需要提交表单

    onclick="var frm = get_form(this); target_popup(frm); frm.submit()">
    


    也就是说,您最好使用常规的提交按钮并应用CSS使其看起来像您想要的样子。

    这将在警报中显示结果,而不是在新窗口中。OP希望在新窗口中呈现结果。“想做什么就做什么”相当模糊,没有解释如何在所有URL正确解析的情况下在新窗口中显示结果。