By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,844 Members | 836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,844 IT Pros & Developers. It's quick & easy.

Submit form to new window

P: n/a
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,sc rollbars=no,
resizable=no,copyhistory=no,width=500,height=500,t op=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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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','...param s...');
myForm.target = 'Popup_Window';
return true;
}
</script>

<form action="submit.php" onSubmit="redirectOutput(this)">
....
</form>
Terence Parker <te*****@parker.com.hk> wrote in message
news:a9**************************@posting.google.c om...
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,sc rollbars=no,
resizable=no,copyhistory=no,width=500,height=500,t op=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

Jul 20 '05 #2

P: n/a
Hi Terence,

Terence Parker wrote:
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,sc rollbars=no,
resizable=no,copyhistory=no,width=500,height=500,t op=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

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.