简体   繁体   中英

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(); which submits the form. Clearfield(); gives a "true" value to the preview variable and 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.

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.

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? You're already using JavaScript, might as well change the form while you're at it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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