Submit form to new window

T

Terence Parker

How does one go about submitting a form with a link - but submitting
it to a new window AND to a page different to that described within
the action="" option of the <form> tag?

Say, for example, I have a simple form such as the following:

<form method="POST" action="submit.php" name="AForm">
Name: <input type="text" name="Name" length="20"><br>
Age: 15 <a href="age.php">change age</a><br>
<input type="submit" name="submit" value="submit">
</form>

Clicking 'submit' will submit to 'submit.php' - but I want the link to
submit to 'age.php'.

This example is an oversimplification of what I want to do - yes, I
know that in the example above I don't NEED to submit a link into a
new window... But, it's an example.

I know one can use ONCLICK="document.formName.submit();return true;" -
but that submits to the same form defined in <form action> .

I know as well that I can use "onClick=window.open('link.php','Popup
Window','toolbar=no,
location=no,directories=no,status=no,menubar=no,scrollbars=no,
resizable=no,copyhistory=no,width=500,height=500,top=20,left=
100')" (or something similar) to open a link to a new window.

But how do I combine the two - AND submit to a different location?

Basically, what i'm doing is one of those pages with customer
information - and for one of those choices I want to popup a new
window with a <select> . That submit will then send the data back to
the originating PHP page - and will reload it.

IDEALLY, I wouldn't even do it like this - just have javascript
replace the values on the originating page without reloading (and
resubmitting everything)... so if anyone knows how to do that, even
better!

Thanks,

Terence
 
V

VK

1. If you just want to open a new default window for output:
<form action="submit.php" target="_blank">

2. If you want to redirect to a window with custom properties (size,
position etc.):
<script>
function redirectOutput(myForm) {
var w = window.open('about:blank','Popup_Window','...params...');
myForm.target = 'Popup_Window';
return true;
}
</script>

<form action="submit.php" onSubmit="redirectOutput(this)">
....
</form>
 
S

Stephen

Hi Terence,

Terence said:
How does one go about submitting a form with a link - but submitting
it to a new window AND to a page different to that described within
the action="" option of the <form> tag?

I'm a little confused here ... You always submit to a web server and
you submit to the action="" uri. The returned content can be directed to
another window.
Say, for example, I have a simple form such as the following:

<form method="POST" action="submit.php" name="AForm">
Name: <input type="text" name="Name" length="20"><br>
Age: 15 <a href="age.php">change age</a><br>
<input type="submit" name="submit" value="submit">
</form>

Clicking 'submit' will submit to 'submit.php' - but I want the link to
submit to 'age.php'.

If you want to submit to "age.php", why put "submit.php" as the value of
the action attribute? Put "age.php" there.
This example is an oversimplification of what I want to do - yes, I
know that in the example above I don't NEED to submit a link into a
new window... But, it's an example.

I know one can use ONCLICK="document.formName.submit();return true;" -
but that submits to the same form defined in <form action> .

That's what it's supposed to do. Now, I do believe you can set the value
of action dynamically, something like

document.forms["formName"].action="uri";

before doing the submit...

I know as well that I can use "onClick=window.open('link.php','Popup
Window','toolbar=no,
location=no,directories=no,status=no,menubar=no,scrollbars=no,
resizable=no,copyhistory=no,width=500,height=500,top=20,left=
100')" (or something similar) to open a link to a new window.

But how do I combine the two - AND submit to a different location?

Basically, what i'm doing is one of those pages with customer
information - and for one of those choices I want to popup a new
window with a <select> . That submit will then send the data back to
the originating PHP page - and will reload it.

IDEALLY, I wouldn't even do it like this - just have javascript
replace the values on the originating page without reloading (and
resubmitting everything)... so if anyone knows how to do that, even
better!
Ah .. so we finally get to what the real need is. I think this last idea
is probably best; forget that popping up of extra windows. If you can do
it without the popups, good. If you can dynamically update the page
without making a round trip to the server, that's probably better, too.

For myself, I'd rather see you post some code with the specifics of what
you want in the <select> and what you'd like to see happen when the user
selects something. That might give a better starting point for advice
that can contribute to the solution that you'd ideally like to implement.

Regards,
Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,299
Latest member
JewelDeLaC

Latest Threads

Top