wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how can I read form fields in another html or jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how can I read form fields in another html or jsp page" Watch "how can I read form fields in another html or jsp page" New topic
Author

how can I read form fields in another html or jsp page

suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Hi,

I have one html page and in that page there are number of hidden fields. But I don't know howmany fields are coming in the URL. How do I read all those fields in when form is submited.
For ex:
<html>
<body>
<form name="form1" action="test1.jsp">
<input type="hidden" name="price1" value="23.34" >
<input type="hidden" name="qty1" value="2">
<input type="hidden" name="price2" value="33" >
<input type="hidden" name="qty2" value="3">
etc....
..........
<input type="submit" name="click" value="Click Here"
</form>
</body>
</html>

In the above html page I don't know how many values are coming in the URL if user clicks "Click Here" button. How do I read all the fields in test1.jsp page. Please can any one provide some sample code.

Thanks,
Suprita.
Balan Raj
Ranch Hand

Joined: Aug 26, 2003
Posts: 74
You need to use the "request" to handle that.

Check the Servelt request API to find that you have getParameterNames().

This will give you all the parameter names that came from the form that you submitted. You just cycle thru the enumeration, to get all the values

Hope this helps
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You want to do this on the server side or client side?

Eric
suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Thanks for your quick response..........
suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Hi,

How do I sent current window form fields to new window.
For example I have one jsp page is like:
<script language="JavaScript1.2">
function disp(){
window.open(test1.jsp);
}
</script>
<body>
<form name="form1">
<input type="hidden" name="price1" value="23.34" >
<input type="hidden" name="qty1" value="2">
<input type="hidden" name="price2" value="33" >
<input type="hidden" name="qty2" value="3">
<input type="hidden" name="price3" value="44" >
<input type="hidden" name="qty3" value="4">
<input type="button" name="click" value="ClickHere" >
</form>
</body>

When I click button it is opening new window. But how to I pass all the hidden variables, text fields to new window. I want to display all these values in new window. Any help please..........
suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Hi,

When I use getParameterNames() to read all the parameter names and correspondig values it is displaying parameter from last to first i.e
if you see the above html code the form fields displaying are
price3 = 44
qty = 4
price2 = 22
qty = 3
etc...
I want the reverse way i.e
price1= 11
qty1 = 1
price2 = 22
qty = 2
etc............
What i have to display form fiels from first to last (by default getParameterNames() is getting parameters from last to first).
suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Hi,

I need to that on server side. My basic stuff is I have one jsp page and that has lot of hidden fields and different button on this page. There is button some thing like "Export". When I click this button I need to dispaly all the hidden fields information in the new window(basically it is another jsp page). If I use getParameterNames() it should display the parameter names in from last to first (from URL). i.e
let say url = "http://.../test.jsp?price1=12&qty1=1&price2=23&qty=2....."
Then getParameterNames() get values like
price3= 324
qty3= 5
price2 = 23
qty2= 2
price1= 12
qty1 = 1
etc..........
I want some thing like
price1 = 12
qty1= 1
price2= 23
qty2 = 2
etc..........

Thanks.
Balan Raj
Ranch Hand

Joined: Aug 26, 2003
Posts: 74
I dont think the API's can help you with that..
What I would suggest is that you have some logic by which you construct these names.. Maybe in form one, have some indicator ( read hidden field) ,which will contain the total number of fields.. for example u have price1 to price5, pass the value 5 as a hidden form.

then in the bean, iterate to find out the values.

you can do a
for(int incr =1; myCount < hiddenFieldValue; incr ++)
if(null != request.getParameter("price"+incr))
PRINT request.getParameter("price"+incr)

hth
suprita konda
Greenhorn

Joined: Sep 20, 2004
Posts: 10
Thanks for your help. The way you told make sence to me..........................
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can I read form fields in another html or jsp page
 
Similar Threads
How to rendar data from new window to old window through window.focus() ? Or any other way.
Wanting to Displaying Empty Data on Initial Search Page
Display of Latin Characters
Submit Methods pulling same data
trying to submit form on another site from my JSP