0

My Requirement

Form Submission in New Window & Redirect Existing Page to a new page on same click.

When I tried only Form submission is happening. Javascript function to redirect is not working.

Html

<form id="feedback.php" name="form1" method="post" action="feedback.php" target="_blank"> <input type="submit" class="button" value="SUMBIT" onclick="btntest_onclick();"/> </form> 

Javascript

<script> function btntest_onclick() { window.location.href("mainpage.php"); } </script> 

Actual

But Only Form Submission is Happening in New Window. Existing Page is not redirected.

Please tell me how to do this ?

2 Answers 2

2

Your HTML :

<form id="feedback.php" name="form1" method="post" action="feedback.php" target="_blank"> <input type="submit" class="button" value="SUMBIT" onClick="btntest_onclick()"/> </form> 

See onClick

Your Javascript :

function btntest_onclick() { setTimeout(function(){ window.location.href = "mainpage.php"; },0); } 

window.location.href is not a function.
And apparently it needs to be async to work.

JsFiddle

Sign up to request clarification or add additional context in comments.

5 Comments

In your example itself from JsFiddle, Current page is redirected! Only form submission is happening. I need to redirect existing page.
Well, then I don't understand what you need exactly. In my example, both the redirection of the current page (frame of html displayed in jsFiddle) and the form's submission are happening. I think, you don't see the redirection because it is a frame (which is redirected to 404) in jsFiddle. Have you tried my code?
Ya i have tried. thats why said its not working. Only form submission in new window is happening... Main page window redirection is not happening...
Ok, I don't understand what happened, but you're right, it wasn't working. I tried that yesterday it was working though. So I updated the jsFiddle. I think it's working now, I simply put the redirection in a setTimeout. jsfiddle.net/9Y5SQ/3 I've edited my answer. Hope it's working for you now.
You're welcome. If it's the solution you were looking for, you should set it as a correct answer to your question.
-1

add onsubmit to your form.
and inside function do something like that:

function btntest_onclick() { window.open("http:// your url"); window.location.href="/mainpage.php"; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.