Google Answers Logo
View Question
 
Q: Javascript: Form post in a popup window ( No Answer,   2 Comments )
Question  
Subject: Javascript: Form post in a popup window
Category: Computers > Programming
Asked by: fr_jericho-ga
List Price: $10.00
Posted: 06 Aug 2004 14:05 PDT
Expires: 08 Aug 2004 11:16 PDT
Question ID: 384516
What I am trying to do:
From java script, I want to open a new window and send several values
to an ASPX page so that they can be read on the server side. Sounds
simple doesn't it?


What I don't want to do:
I am concerned that one of the string values I'm trying to send to the
ASPX might be very long. In fact, it may be so long that it could be
longer than what IE can accept.

This limitation is discussed in Microsoft KB article number 20847: 

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q208/4/27.ASP&NoWebContent=1.
This means that a solution like the

following is unacceptable to me:
window.open("ThePage.ASPX?var1=123&var2=456", "MyNewWindow",
"width=750,height=510,status=1,resizable=1");
It's unacceptable because var1 and var2 are passed on the QueryString
and the values they contain will be truncated if it exceeds the limit
imposed by IE.


What I'm thinking about doing:
I thinking about opening a new window and using document.write to
"inject" the <form method='post'> and several <input> tags and finally
posting the form.


What I have tried so far:
I created a simple html page with a little bit of javascript and also
an ASPX that simply displays the values that have been passed to it.
This is meant to be a simple

"proof of concept". Here is the content of the html page:
<html>
<head>
<script language="javascript">
var iPageNumber = 1;
var strURL = "http://MyServer/PopupTest.aspx";
strURL += "?QsItem1=abc";
strURL += "&QsItem2=xyz";
var oExportWindow = window.open("", "ExportWindow",
"width=750,height=510,status=1,resizable=1");
oExportWindow.document.write("<html><body>");
oExportWindow.document.write("<form id='frmExport' method='post'
action=" + String.fromCharCode(34) + strURL + String.fromCharCode(34)
+ ">");
oExportWindow.document.write("<input type='text' id='FormItem1'
value='123'></input>");
oExportWindow.document.write("<input type='hidden' id='FormItem1'
value='456'></input>");
oExportWindow.document.write("</form>");
oExportWindow.document.write("</body></html>");
alert('Number of items in the form before submitting: ' +
oExportWindow.document.all.frmExport.length);
oExportWindow.document.all.frmExport.submit();
</script>
</head>
<body>
Popup test in progress...
</body>
</html>

Here is the content of the ASPX page:
<html>
<head>
<title>Server side poup test</title>
</head>
<script runat="server">
	public void Page_Load(Object sender,EventArgs e) {
		Response.Write("Number of items on the QueryString: " +
Request.QueryString.Count + " <-- This should be 2<br>");
		Response.Write("Number of items on the Form: " + Request.Form.Count
+ " <-- This should also be 2<br>");
	}
</script>
<body>
</body>
</html>


What is wrong with my "proof of concept":
In the client side code, I send 2 items on the QueryString and 2 items
in the Form but on the server side only the 2 QueryString items are
received. Tthe two items in the

form are missing!?!?!?!?!?!?


What I'm looking for:
I would like some help figuring out why the form items are missing
when the html is posted to the server side ASPX page. I am also opened
to suggestions to achieve my

goal, as long as it doesn't involve using the QueryString because of
the limitation I menti
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript: Form post in a popup window
From: crythias-ga on 06 Aug 2004 19:17 PDT
 
any chance you could split up the variable var11 and var12 and var21 and var22?

And/or store in a cookie? :)
Subject: Re: Javascript: Form post in a popup window
From: joey-ga on 06 Aug 2004 19:50 PDT
 
I'm not an ASP developer, but I'm guessing that your problem is in
your ASP code (are you checking for POST variables accurately?) 
Because if your form is submitting (which it appears to be), there's
no reason the input fields shouldn't be travelling with it.

As a note, both of your input fields have the same name.  I'm not sure
how ASP is going to interpret two fields with the same name.

Regarding how you're doing this though, I think you're adding an
unnecessary level of complication.  Instead of popping up a window and
JS-writing a form in there to submit, I would create a real HTML form
in the base (main) window with the proper action and inputs (you could
hide it at the bottom of the main page if you want).  For that form,
in the form declaration, enter:
    onSubmit="openWindow(this);
Then, in the javascript at the top, use a function like this:

--------
function openWindow(myLink) {
        if(! window.focus)return;
        var myWin=window.open("","NewWindow","height=430,width=555,dependent=no,scrollbars=yes,resizable=no");
        myWin.focus();
        myLink.target="NewWindow";
}
--------

That will take the form's data and submit it into the new window.  You
can then add another line that automatically submits the real form
when the main page loads.  It will, in turn, call "openWindow" as it
submits, forcing it into the new window.

Doing this saves the onerous extra step of dynamically writing a form.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy