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

How to submit a form in a popup window?

P: n/a
using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?

Thanks.
--
V
Aug 6 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 8/7/2008 4:31 AM India Time, _V S Rawat_ wrote:
using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?

Thanks.
could anyone recommend a newsgroup on javascript for newbies where I can
ask my queries.
thanks.
Aug 7 '08 #2

P: n/a

V S Rawat schreef:
On 8/7/2008 4:31 AM India Time, _V S Rawat_ wrote:
>using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?

Thanks.

could anyone recommend a newsgroup on javascript for newbies where I can
ask my queries.
This one is fine.

Regards,
Erwin Moller
>

thanks.

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 7 '08 #3

P: n/a

V S Rawat schreef:
using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")
OK so far.
>
There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?

Submit it to where?
If your popupwindow has a form, it can also submit it, just as all other
pages.
If you have something like the following code in your popup, you should
be fine:

<form action="somescript.php" method="Post>
Your name: <input type="text" name="firstname">
<input type="submit" value="Post me">
</form>

If you are asking: "How do I post my form to a webpage" the answer is
simple: You don't.
Forms are NOT send to a HTML document, but to a script on some server
(named 'somescript.php' in my above example) that is able to receive the
forminformation.

However, you CAN tranfer the information filled in to some other window
(using JavaScript).

Is THAT what you are after?

Regards,
Erwin Moller
Thanks.

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 7 '08 #4

P: n/a
On Aug 7, 4:53*am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
V S Rawat schreef:
using Javascript, I am opening a web-based url in a popup window.
MyWin1=Window.Open(url, "mywindow")

OK so far.
Not from where I am sitting.

And I don't know what the OP wants either.
Aug 7 '08 #5

P: n/a
V S Rawat wrote:
On 8/7/2008 4:31 AM India Time, _V S Rawat_ wrote:
>using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")
Should be at least:

var myWin1 = window.open(url, "mywindow", "resizable,scrollbars");

ECMAScript implementations are case-sensitive (unless you are mistaken that
you are using "Javascript" in the first place), and the minimum features
argument is necessary for meeting accessibility guidelines (and legislation).
>There is a form (form1) in the url in that popup window,
Not in the URL, but in the (HTML) document referred to by the URL. The
URL (Uniform Resource Locator) is but an address. You live in a house (or a
tent, or a cave, or ... ;-)), not in an address, don't you?
>I need to submit that form.

How do I submit that form1 from the javascript from my current window?
I will assume you mean the popups opener by "current window". Suppose then
"form1" is the value of the `form' element's `name' or `id' attribute (the
latter not as well supported by this):

myWin1.document.forms["form1"].submit();

(Easy and most obvious, isn't it?) However, users will not take kindly on
content being submitted without them agreeing to it explicitly. What do you
think you need this for anyway?
could anyone recommend a newsgroup on javascript for newbies where I can
ask my queries.
If a newsgroup existed where only newbies were posting, it could obviously
not be recommended here, because there you would inevitably receive the
worst kind of help possible, making you to stay a newbie forever: blind
leading the blind.

So ISTM you are not asking for a newsgroup for newbies, but for lusers.
Fortunately, AFAIK there is no such newsgroup in the Big 8. (From
crossposts getting in here now and then, it would appear alt.ALL quite often
provides the cuddly, self-deceived, incompetent, dangerous kind of help that
you are asking for.)

In fact, this newsgroup is for newbies as well, provided they take heed of
the well-meaning recommendations in the FAQ and FAQ Notes, and do not play
stupid like this.

<http://jibbering.com/faq/>
Score adjusted

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Aug 7 '08 #6

P: n/a
On 8/7/2008 4:01 PM India Time, _Thomas 'PointedEars' Lahn_ wrote:
V S Rawat wrote:
>On 8/7/2008 4:31 AM India Time, _V S Rawat_ wrote:
>>using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

Should be at least:

var myWin1 = window.open(url, "mywindow", "resizable,scrollbars");

ECMAScript implementations are case-sensitive (unless you are mistaken that
you are using "Javascript" in the first place), and the minimum features
argument is necessary for meeting accessibility guidelines (and legislation).
oops! I was trying it all in JavaScript shell that I am used to use for
my greasemonkey script debugging, so I didn't pay attention to these
differences.

thanks for correcting in the first step itself.
>
>>There is a form (form1) in the url in that popup window,

Not in the URL, but in the (HTML) document referred to by the URL. The
URL (Uniform Resource Locator) is but an address. You live in a house (or a
tent, or a cave, or ... ;-)), not in an address, don't you?
perfectly correct.

There is a form (by the name form1) in the html that was opened from
that url in the popup window by this javascript.
>
>>I need to submit that form.

How do I submit that form1 from the javascript from my current window?

I will assume you mean the popups opener by "current window". Suppose then
"form1" is the value of the `form' element's `name' or `id' attribute (the
latter not as well supported by this):

myWin1.document.forms["form1"].submit();

(Easy and most obvious, isn't it?) However, users will not take kindly on
content being submitted without them agreeing to it explicitly. What do you
think you need this for anyway?
I am doing some info aggregation from that page that I am opening in the
popup window.

That form actually is submitted by a "search" button. there are some
fields in which various combinations of options are put (that I am doing
by javascript) and then the search button is pressed (form is submitted).

Each setting of options fetches different set of results from the
website that get displayed on the next page. I am saving all such pages,
agreegating their data into a single set, alongwith the option taht
caused that set of data to show up.
>
>could anyone recommend a newsgroup on javascript for newbies where I can
ask my queries.

If a newsgroup existed where only newbies were posting, it could obviously
not be recommended here, because there you would inevitably receive the
worst kind of help possible, making you to stay a newbie forever: blind
leading the blind.

So ISTM you are not asking for a newsgroup for newbies, but for lusers.
Fortunately, AFAIK there is no such newsgroup in the Big 8. (From
crossposts getting in here now and then, it would appear alt.ALL quite often
provides the cuddly, self-deceived, incompetent, dangerous kind of help that
you are asking for.)
No way. There are so many "empty" ngs on net that I was not sure on
picking up the right one. I had subbed to a few more and then unsubbed.
This one was showing traffic but when my post didn't fetch a single
reply in 8+ hours, I started having doubt that it might also be an
"empty" ng, so I had asked.
>
In fact, this newsgroup is for newbies as well, provided they take heed of
the well-meaning recommendations in the FAQ and FAQ Notes, and do not play
stupid like this.

<http://jibbering.com/faq/>
oh, I normally follow the murphy's laws cousin:

"when nothing that you can think of works, read the manual."
>
Score adjusted

PointedEars
Thanks.
--
V
Aug 7 '08 #7

P: n/a
On 8/7/2008 2:23 PM India Time, _Erwin Moller_ wrote:
V S Rawat schreef:
>using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

OK so far.
>There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?


Submit it to where?
submit that to its net server where some script will take the other
inputs supplied by the form1 and return data to the popup window.
If your popupwindow has a form, it can also submit it, just as all other
pages.
If you have something like the following code in your popup, you should
be fine:

<form action="somescript.php" method="Post>
Your name: <input type="text" name="firstname">
<input type="submit" value="Post me">
</form>

If you are asking: "How do I post my form to a webpage" the answer is
simple: You don't.
no, no. that is a url opened in that popup page and its form is to be
submitted to the mothership.
Forms are NOT send to a HTML document, but to a script on some server
(named 'somescript.php' in my above example) that is able to receive the
forminformation.
yeah, that is what is happening.
>
However, you CAN tranfer the information filled in to some other window
(using JavaScript).

Is THAT what you are after?
once I submit the form in the popup window and it returns with some
data, I have to transfer that data to some other window or better to
some disk file. dos copy command can combine several files in one go,
that windows GUI just is not able to do.
>
Regards,
Erwin Moller
--
V
Aug 7 '08 #8

P: n/a

V S Rawat schreef:
On 8/7/2008 2:23 PM India Time, _Erwin Moller_ wrote:
>V S Rawat schreef:
>>using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")

OK so far.
>>There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?


Submit it to where?

submit that to its net server where some script will take the other
inputs supplied by the form1 and return data to the popup window.
Hi,

For clearity's sake, lets name all the objects. :-)

You have:
1) Your basic window, let call it 'mainwindow'.
It has some button or hyperlink that creates a new window.

2) Your popupwindow. Lets name it 'popupwin'.
This popupwin has a form we call 'form1'.
Lets say form1 has the action-attribute action="processform1.php"
>
>If your popupwindow has a form, it can also submit it, just as all
other pages.
If you have something like the following code in your popup, you
should be fine:

<form action="somescript.php" method="Post>
Your name: <input type="text" name="firstname">
<input type="submit" value="Post me">
</form>

If you are asking: "How do I post my form to a webpage" the answer is
simple: You don't.

no, no. that is a url opened in that popup page and its form is to be
submitted to the mothership.
>Forms are NOT send to a HTML document, but to a script on some server
(named 'somescript.php' in my above example) that is able to receive
the forminformation.

yeah, that is what is happening.
>>
However, you CAN tranfer the information filled in to some other
window (using JavaScript).

Is THAT what you are after?

once I submit the form in the popup window and it returns with some
data, I have to transfer that data to some other window or better to
some disk file. dos copy command can combine several files in one go,
that windows GUI just is not able to do.
Erm......
Dos?
Filesystem and files?
These things are NOT accessible by JavaScript under normal circumstances.
Suppose you are browsing the internet and you come across a webpage that
starts modifying your filesystem?
Or starts calling DOS commands?
That is why JavaScript lives in a box in your webbrowser, and cannot
reach futher (unless you run older IE versions).

If you ask how you can let the server give back a webpage that tells
something via Javascript to mainwin (after posting form1 from popupwin),
that is easy.

1) After the server receives the form1 information (via the abovedefined
script processform1.php), it responds with:
[example in PHP code]

... doctype html.. body.. etc
<script type="text/javascript">
var serverresponse = "<?php echo "Hi, this is the serverresponse"; ?>";
// You can add more of course.
// Now you have a variable in javascript named serverresponse that
// holds something.

// Tell the mainwin about it:
var myMainWin = window.opener;
myMainWin.setResponse(serverresponse);

// Optionally close the popup with:
window.close();
</script>

In your mainwin you must have a JavaScriptfunction defined setResponse,
for example:

function setResponse(someResponse){
alert ("This is mainwindow talking. I received from
popup:"+someresponse);
}

Hope that helps.

Regards,
Erwin Moller

PS: Code not tested.

>
>>
Regards,
Erwin Moller

--
V

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 8 '08 #9

P: n/a
On 8/8/2008 2:11 PM India Time, _Erwin Moller_ wrote:
V S Rawat schreef:
>On 8/7/2008 2:23 PM India Time, _Erwin Moller_ wrote:
>>V S Rawat schreef:
using Javascript, I am opening a web-based url in a popup window.

MyWin1=Window.Open(url, "mywindow")
OK so far.

There is a form (form1) in the url in that popup window, I need to
submit that form.

How do I submit that form1 from the javascript from my current window?
Submit it to where?
submit that to its net server where some script will take the other
inputs supplied by the form1 and return data to the popup window.

Hi,

For clearity's sake, lets name all the objects. :-)

You have:
1) Your basic window, let call it 'mainwindow'.
It has some button or hyperlink that creates a new window.

2) Your popupwindow. Lets name it 'popupwin'.
This popupwin has a form we call 'form1'.
Lets say form1 has the action-attribute action="processform1.php"
>>If your popupwindow has a form, it can also submit it, just as all
other pages.
If you have something like the following code in your popup, you
should be fine:

<form action="somescript.php" method="Post>
Your name: <input type="text" name="firstname">
<input type="submit" value="Post me">
</form>

If you are asking: "How do I post my form to a webpage" the answer is
simple: You don't.
no, no. that is a url opened in that popup page and its form is to be
submitted to the mothership.
>>Forms are NOT send to a HTML document, but to a script on some server
(named 'somescript.php' in my above example) that is able to receive
the forminformation.
yeah, that is what is happening.
>>However, you CAN tranfer the information filled in to some other
window (using JavaScript).

Is THAT what you are after?
once I submit the form in the popup window and it returns with some
data, I have to transfer that data to some other window or better to
some disk file. dos copy command can combine several files in one go,
that windows GUI just is not able to do.

Erm......
Dos?
Filesystem and files?
These things are NOT accessible by JavaScript under normal circumstances.
Suppose you are browsing the internet and you come across a webpage that
starts modifying your filesystem?
Or starts calling DOS commands?
That is why JavaScript lives in a box in your webbrowser, and cannot
reach futher (unless you run older IE versions).
My holy Gowd, I haven't thought about that.

That punctures my entire algorithm of how to do this work.
>
If you ask how you can let the server give back a webpage that tells
something via Javascript to mainwin (after posting form1 from popupwin),
that is easy.

1) After the server receives the form1 information (via the abovedefined
script processform1.php), it responds with:
[example in PHP code]

.. doctype html.. body.. etc
<script type="text/javascript">
var serverresponse = "<?php echo "Hi, this is the serverresponse"; ?>";
// You can add more of course.
// Now you have a variable in javascript named serverresponse that
// holds something.

// Tell the mainwin about it:
var myMainWin = window.opener;
myMainWin.setResponse(serverresponse);

// Optionally close the popup with:
window.close();
</script>

In your mainwin you must have a JavaScriptfunction defined setResponse,
for example:

function setResponse(someResponse){
alert ("This is mainwindow talking. I received from
popup:"+someresponse);
}

Hope that helps.
Hmm, not enough for a newbie, I guess.

There are 13 full pages of data (say, with 100 records each) that would
be given back by the server in response to the submit form1.

It would be listed as 1,2,...,12,13 links (to each of the 13 pages), and
only such 3-4 links would be displayed on any page, but other nearby
pages' links will be there.

I have to pick those 13 pages and merge those data and save in a dos file.

It is just not convenient to transfer such volume of received data back
to mainwindow for saving, can't

Can't I just save each page on the disk, in the popup window itself? or
fetch the link of the 13 pages each time and transfer that link back to
mainwindow, for saving either just the 13 links or fetching and saving
the 13 files from those links?

At least, then, I can run some other command, like launch an excel file
with a VBA macro that would then process those 13 files.

A javascript should be able to save files/ data on the disk. After all,
we do save, files in browser.
>
Regards,
Erwin Moller

PS: Code not tested.

>>Regards,
Erwin Moller
--
V
Thanks.
--
V
Aug 8 '08 #10

P: n/a

V S Rawat schreef:
On 8/8/2008 2:11 PM India Time, _Erwin Moller_ wrote:
>V S Rawat schreef:
>>On 8/7/2008 2:23 PM India Time, _Erwin Moller_ wrote:

V S Rawat schreef:
using Javascript, I am opening a web-based url in a popup window.
>
MyWin1=Window.Open(url, "mywindow")
OK so far.

There is a form (form1) in the url in that popup window, I need to
submit that form.
>
How do I submit that form1 from the javascript from my current window?
>

Submit it to where?
submit that to its net server where some script will take the other
inputs supplied by the form1 and return data to the popup window.

Hi,

For clearity's sake, lets name all the objects. :-)

You have:
1) Your basic window, let call it 'mainwindow'.
It has some button or hyperlink that creates a new window.

2) Your popupwindow. Lets name it 'popupwin'.
This popupwin has a form we call 'form1'.
Lets say form1 has the action-attribute action="processform1.php"
>>>If your popupwindow has a form, it can also submit it, just as all
other pages.
If you have something like the following code in your popup, you
should be fine:

<form action="somescript.php" method="Post>
Your name: <input type="text" name="firstname">
<input type="submit" value="Post me">
</form>

If you are asking: "How do I post my form to a webpage" the answer
is simple: You don't.
no, no. that is a url opened in that popup page and its form is to be
submitted to the mothership.

Forms are NOT send to a HTML document, but to a script on some
server (named 'somescript.php' in my above example) that is able to
receive the forminformation.
yeah, that is what is happening.

However, you CAN tranfer the information filled in to some other
window (using JavaScript).

Is THAT what you are after?
once I submit the form in the popup window and it returns with some
data, I have to transfer that data to some other window or better to
some disk file. dos copy command can combine several files in one go,
that windows GUI just is not able to do.

Erm......
Dos?
Filesystem and files?
These things are NOT accessible by JavaScript under normal circumstances.
Suppose you are browsing the internet and you come across a webpage
that starts modifying your filesystem?
Or starts calling DOS commands?
That is why JavaScript lives in a box in your webbrowser, and cannot
reach futher (unless you run older IE versions).

My holy Gowd, I haven't thought about that.

That punctures my entire algorithm of how to do this work.
Sorry. :-(

>
>>
If you ask how you can let the server give back a webpage that tells
something via Javascript to mainwin (after posting form1 from
popupwin), that is easy.

1) After the server receives the form1 information (via the
abovedefined script processform1.php), it responds with:
[example in PHP code]

.. doctype html.. body.. etc
<script type="text/javascript">
var serverresponse = "<?php echo "Hi, this is the serverresponse"; ?>";
// You can add more of course.
// Now you have a variable in javascript named serverresponse that
// holds something.

// Tell the mainwin about it:
var myMainWin = window.opener;
myMainWin.setResponse(serverresponse);

// Optionally close the popup with:
window.close();
</script>

In your mainwin you must have a JavaScriptfunction defined
setResponse, for example:

function setResponse(someResponse){
alert ("This is mainwindow talking. I received from
popup:"+someresponse);
}

Hope that helps.

Hmm, not enough for a newbie, I guess.

There are 13 full pages of data (say, with 100 records each) that would
be given back by the server in response to the submit form1.

It would be listed as 1,2,...,12,13 links (to each of the 13 pages), and
only such 3-4 links would be displayed on any page, but other nearby
pages' links will be there.

I have to pick those 13 pages and merge those data and save in a dos file.

It is just not convenient to transfer such volume of received data back
to mainwindow for saving, can't

Can't I just save each page on the disk, in the popup window itself? or
fetch the link of the 13 pages each time and transfer that link back to
mainwindow, for saving either just the 13 links or fetching and saving
the 13 files from those links?
If you develop a webapplication, you must design it rigth (duh).
In this case, you designed it in a way where you didn't give it any
thought WHERE the data actually goes.
That is the problem.

I think it is best for you to solve this issue SERVERSIDE. No need for
JavaScript, only maybe to open a window or give focus to the right
formelements.

I saw you posting in comp.lang.php (without googlegroups, good!).
PHP is a great language to script you on the server.

So learn PHP (if you hadn't already) and let PHP do the merging of the data.
>
At least, then, I can run some other command, like launch an excel file
with a VBA macro that would then process those 13 files.

A javascript should be able to save files/ data on the disk. After all,
we do save, files in browser.
Well, you cannot save files with JavaScript. Period.
You can safe some info in a cookie, but that is really messy, and not
suited for many pages filled with data. (Most browsers accept only a few
KiloBytes for a cookie).

Go serverside. There lies your solution.

Good luck!

Regards,
Erwin Moller

>
>>
Regards,
Erwin Moller

PS: Code not tested.

>>>Regards,
Erwin Moller
--
V

Thanks.
--
V

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 8 '08 #11

P: n/a
V S Rawat wrote:
On 8/7/2008 4:01 PM India Time, _Thomas 'PointedEars' Lahn_ wrote:
>V S Rawat wrote:
>>could anyone recommend a newsgroup on javascript for newbies where I can
ask my queries.
If a newsgroup existed where only newbies were posting, it could obviously
not be recommended here, because there you would inevitably receive the
worst kind of help possible, making you to stay a newbie forever: blind
leading the blind.

So ISTM you are not asking for a newsgroup for newbies, but for lusers.
Fortunately, AFAIK there is no such newsgroup in the Big 8. (From
crossposts getting in here now and then, it would appear alt.ALL quite often
provides the cuddly, self-deceived, incompetent, dangerous kind of help that
you are asking for.)

No way. There are so many "empty" ngs on net that I was not sure on
picking up the right one. I had subbed to a few more and then unsubbed.
This one was showing traffic but when my post didn't fetch a single
reply in 8+ hours, I started having doubt that it might also be an
"empty" ng, so I had asked.
The news server your picked for posting (aioe.org) is not exactly a good
one, which would appear to apply not only to its reputation (as mainly being
the source of troll and spam postings due to its "everything allowed, for
free, no authentication" policy) but also to its news feed.

Between your OP at 2008-08-07T01:01+0200 and your followup at
2008-08-07T09:14+0200, 6 postings have arrived here (which is quite good
considering that many knowledgeable regulars would rather be working, going
out or be asleep at that time), and e.g. Google Groups shows that this is
quite an active newsgroup. In addition, your question was worded badly; I
just happened to guess your meaning correctly. See also
<http://jibbering.com/faq/#FAQ2_4>.

Please trim your quotes, see <http://jibbering.com/faq/#FAQ2_3pp.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 10 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.