我想使用 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>
这里发生的情况是,当我希望将表单加载到弹出页面内时,显示了弹出窗口,但表单已加载到主页上。另外,我只能使用此处的链接来访问表单,因为不允许使用提交按钮。
最佳答案
您正在提交表单,然后将调用 submit()
的返回值传递给 target_popup()
。
您需要首先调用target_popup()
并向其传递表单,然后您需要提交表格。
onclick="var frm = get_form(this); target_popup(frm); frm.submit()">
<小时/>
也就是说,您最好使用常规提交按钮并应用 CSS 使其看起来像您想要的那样。
关于javascript - 提交表单并使用 href 标签在弹出窗口中打开它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38629187/