When I submit the form I'm trying to open a new window tab and pass the values over into the new window tab. Then I need the parent page to redirect to the next page.
The problem is the form values are not passing to the new window tab. How could I do that with the following code I have right now?
<form class="form" id="promo_form" method="post">
<input type="text" name="first_name" id="first_name">
<input type="text" name="last_name" id="last_name">
<input type="text" name="zipcode" id="zipcode" maxlength="5">
<button type="submit" id="promo_form_button" class="submit">Continue</button>
</form>
$(document).ready(function($){
var form = document.getElementById("promo_form");
function goToUrl(){
window.open("", "_blank");
window.location = ""
}
document.getElementById("promo_form_button").onclick = goToUrl;
});
When I submit the form I'm trying to open a new window tab and pass the values over into the new window tab. Then I need the parent page to redirect to the next page.
The problem is the form values are not passing to the new window tab. How could I do that with the following code I have right now?
<form class="form" id="promo_form" method="post">
<input type="text" name="first_name" id="first_name">
<input type="text" name="last_name" id="last_name">
<input type="text" name="zipcode" id="zipcode" maxlength="5">
<button type="submit" id="promo_form_button" class="submit">Continue</button>
</form>
$(document).ready(function($){
var form = document.getElementById("promo_form");
function goToUrl(){
window.open("https://site./new-tab", "_blank");
window.location = "https://site./parent-next-page"
}
document.getElementById("promo_form_button").onclick = goToUrl;
});
Share
Improve this question
asked Nov 18, 2013 at 20:32
user23792user23792
431 gold badge1 silver badge4 bronze badges
1 Answer
Reset to default 4Why use window.open when a form can target a new tab/window itself.
HTML:
<form target="_blank" method="get" action="http://google." id="myForm">
<label for="q">Search: </label><input type="text" id="q" name="q" />
<input type="submit" value="search" />
</form>
JavaScript:
document.getElementById("myForm").onsubmit = function() {
window.location.href = "http://www.jsfiddle";
return false;
};
Example:
JSFiddle