submit form data to a new window failed using HTTP POST

M

Matt

The following program submit a FORM DATA to a new window using HTTP
POST,
and postprocess.jsp couldn't get the form data. If I do in GET method
and pass by query string in windowURL, then it works. But I need HTTP
POST method, and I cannot use target="_blank" because I need to
control the new window's properties (disable the scrollbars, menubars,
etc...)

Are there any workarounds?

<html>
<script type="text/javascript">
function checkAndSubmitForm(theForm)
{
var windowURL = theForm.action;
window.open(windowURL, "newWin",
"scrollbars=0,menubar=0,toolbar=0,location=0,status=0");
}
</script>

<body>
<FORM NAME="formname" method="POST" action="postprocess.jsp">
<P><input type=text" name="username"/>
<P><input type="button" name="submitBtn" value="Submit Form"
onClick="checkAndSubmitForm(document.formname)">
</FORM>
</body>
</html>

postprocess.jsp is just one line statement to get the form data
<%= Request.Form() %>


any ideas? please help!! thanks!!
 
A

Adrienne

Gazing into my crystal ball I observed (e-mail address removed) (Matt)
writing in
The following program submit a FORM DATA to a new window using HTTP
POST,
and postprocess.jsp couldn't get the form data. If I do in GET method
and pass by query string in windowURL, then it works. But I need HTTP
POST method, and I cannot use target="_blank" because I need to
control the new window's properties (disable the scrollbars, menubars,
etc...)

Why do you want to do that? Please do not mess with my browser. I hate
what you want to do.
Are there any workarounds?

Yes, submit to another page, sure, but just use the same window.
<html>
<script type="text/javascript">
function checkAndSubmitForm(theForm)
{
var windowURL = theForm.action;
window.open(windowURL, "newWin",
"scrollbars=0,menubar=0,toolbar=0,location=0,status=0");
}
</script>

Where is your HEAD element?
<body>
<FORM NAME="formname" method="POST" action="postprocess.jsp">

IIRC you must define the name of the form that is going to be used by your
javascript here, so <form name="theform" method="post"
action="postprocess.jsp">
<P><input type=text" name="username"/>
<P><input type="button" name="submitBtn" value="Submit Form"
onClick="checkAndSubmitForm(document.formname)"> </FORM> </body> </html>

Your javascript is looking for the value of the action attribute of the
form element. It will not know what to do because it is expecting
"theform" and the value that is being passed is "formname".
postprocess.jsp is just one line statement to get the form data
<%= Request.Form() %>


any ideas? please help!! thanks!!

Get rid of the idea of opening a window without menu, scrollbar, etc. Also
think about visitors without javascript who will not get your silly window
anyway.
 
J

Jukka K. Korpela

The following program submit a FORM DATA to a new window

Well, it doesn't, but presumably you would like it to work that way.

The best advice is: think twice before wanting that, and if the result is
that you still want it, think again.
I cannot use target="_blank" because I need to

The second best advice is to use a target="..." attribute in a <form>
tag, with a value that does not otherwise appear as window or frame name
in your design, and use JavaScript to _only_ open a new window with that
name and with the desired properties, leaving its content empty (it will
be filled by your form handler, of course). For details & examples see
http://www.cs.tut.fi/~jkorpela/forms/javascript.html#window
<input type="button" name="submitBtn" value="Submit Form"
onClick="checkAndSubmitForm(document.formname)">

That way the form would not work at all when JavaScript is disabled or
filtered out, and the user would see this only after filling out all the
data and trying to click on the button. So use input type="submit".
 
S

SpaceGirl

Adrienne said:
Gazing into my crystal ball I observed (e-mail address removed) (Matt)
writing in



Why do you want to do that? Please do not mess with my browser. I hate
what you want to do.




Yes, submit to another page, sure, but just use the same window.




Where is your HEAD element?




IIRC you must define the name of the form that is going to be used by your
javascript here, so <form name="theform" method="post"
action="postprocess.jsp">



Your javascript is looking for the value of the action attribute of the
form element. It will not know what to do because it is expecting
"theform" and the value that is being passed is "formname".




Get rid of the idea of opening a window without menu, scrollbar, etc. Also
think about visitors without javascript who will not get your silly window
anyway.

Too generic. What if the page is on an Intranet, or part of an in-house
application, or part of some extranet application? Then, just like any
other software application, it'd be quite reasonable ask for things like
this to be enabled...

One of the projects I'm working on right now is a web-based application.
It uses some nasty scripting, but that's fine as it's part of the
specification of the application. It works in FF and IE, but it REQUIRES
scripting, and REQUIRES degrees of window control. It says so on the
back of the box the application ships in :)

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
J

Juhani M?ntt?ri

Adrienne said:
Get rid of the idea of opening a window without menu, scrollbar, etc. Also
think about visitors without javascript who will not get your silly window
anyway.

I fully agree on that!

But you can do that by using <form action="blah.jsp" target="_blank">,
but consider that seriously, 'cause opening pop-ups will get quite
annoying. Plus that most of the time I use a browser it has pop-ups
blocked, and so do many many other users as well.
 
M

Mark Parnell

Too generic. What if the page is on an Intranet, or part of an in-house
application, or part of some extranet application?

Then the OP should have said that, as it is assumed that the question is
in a www context, unless otherwise specified.
 
I

Isofarro

Matt said:
postprocess.jsp is just one line statement to get the form data
<%= Request.Form() %>

JSP? Unless you have defined and imported a static class called Request, or
instantiated an object with the reference "Request", along with an oddly
named method called "Form()", then the above isn't going to work.

The form data in a JSP page is retrieved using the getParameter() method of
the request object. So a field called "clientName" is retrieved using the
expression <%= request.getParameter("clientName") %>
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top