我有一个表单,我需要有两种提交表单的方式。第一种方法是使用标准提交按钮。这工作得很好。第二种方式应该是先打印页面,然后显示警报,最后提交表单。第二种方式是我需要帮助的地方。
对于第二种方式,我在表单中有一个调用“printpage”函数的按钮。此功能打印页面,显示警报,然后应该提交表单。除了提交表单之外,它会做所有事情。任何找出原因的帮助表示赞赏。
htm 页面的代码如下所示。
<body>
<script type="text/javascript">
function printpage()
{
if (MbrForm_Validator(document.forms["MbrForm"]))
{
window.print();
alert("Thank you for your support of the Friends. Please mail your form and check to the address shown on the printed page.");
//***********************************************************************************
//***********************************************************************************
//this is the line of code that does not work for me
document.forms["MbrForm"].submit();
//***********************************************************************************
//***********************************************************************************
}
}
function MbrForm_Validator(theform)
{
//removed for brevity
}
</script>
<h1>Membership Application</h1>
<p style="margin:0px;text-size:9px;"><sup class="required">*</sup>Denotes required information</p>
<form id="MbrForm" name="MbrForm" method="post" action="membertest.php" onsubmit="return MbrForm_Validator(this)" target="_blank">
为简洁起见,表格本身的内容已被删除。仅保留 SUBMIT 和 PRINT 按钮
<table width="75%" border="0" align="center" cellspacing="5" class="displayonly">
<caption style="border-bottom:black solid 1px;">
How Would You Like to Pay?
</caption>
<tr>
<td width="49%" valign="top">
With a check<br />
Click the "Print" button below to print this form for mailing in with your check.
</td>
<td width="51%" valign="top">
On-Line with a Credit Card<br />
Click the "Submit" button below to submit your information and pay using a credit card or PayPal.
</td>
</tr>
<tr>
<td>
<div align="left">
<input type="button" name="btnprint" id="btnprint" value="Print" onclick="printpage()" />
</div>
</td>
<td>
<div align="left">
<input type="submit" name="submit" id="submit" value="Submit" />
</div>
</td>
</tr>
</table>
</form>
<div class="printonly">
<p>
<br /><br /><br /><br /><br />
<hr />
Mail with your check to:<br />
</p>
</div>
</div>
</div>
</body>