简体   繁体   English

在没有target =“_ blank”的新页面中提交表单

[英]Submit form in new page without target=“_blank”

I have two different buttons that submit the same form. 我有两个不同的按钮提交相同的表单。 One submits the form and then runs a database query and the other gives you a preview of what the query will look like. 一个提交表单然后运行数据库查询,另一个提供查询查看内容的预览。

I want the preview to open in a new page, but otherwise for it to open in the same page 我希望预览在新页面中打开,否则在同一页面中打开

Here are my buttons: 这是我的按钮:

<input type="button" onclick="ClearField2(); upload();" value="CREATE YOUR CAMPAIGN!" STYLE="margin-top: 20px; margin-left: 10px; float: left;" class="btn" />
<div style="margin-top: 20px; margin-left: 10px; float: left;">
<input type="button" onclick="ClearField(); upload();" value="OR PREVIEW FIRST!" STYLE="" class="btn"><br>

They both run upload(); 他们都运行upload(); which submits the form. 提交表格。 Clearfield(); gives a "true" value to the preview variable and Clearfield2(); 为预览变量和Clearfield2();提供“true”值Clearfield2(); gives a "false" one. 给出一个“虚假的”。 True tells it to not run the DB Query and to show the preview where False tells it to run the query and show a success message. True告诉它不运行数据库查询并显示预览,其中False告诉它运行查询并显示成功消息。

Obviously, to submit the form in a new page I can add target="_blank" to the <form> tag, but this forces submission in a new page no matter which button was clicked. 显然,要在新页面中提交表单,我可以将target =“_ blank”添加到<form>标记,但这会强制在新页面中提交,无论单击哪个按钮。

Is there any way to tell it to submit the form in a new page based on which button was clicked? 有没有办法告诉它根据点击的按钮在新页面中提交表单?

Dynamically add the target="_blank" in your ClearField function? ClearField函数中动态添加target="_blank" You're already using JavaScript, might as well change the form while you're at it. 您已经在使用JavaScript,也可以在您使用时更改表单。

document.getElementById('form_element_id').setAttribute('target', '_blank')

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

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