File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Problem retaining form field after submission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem retaining form field after submission" Watch "Problem retaining form field after submission" New topic

Problem retaining form field after submission

Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
Hi pals,i am performing the following on my
After loading the page,if the user selects an option from a dropdown.I need to populate the entire form with the result of a query.the query was run with fields from the previous page and the current page dropdown selected value attribute.
To achieve this i called a Javascript function onchange of the select control,which does the following : get the value of the selected option , set the value of a hidden field which holds the next page (which is same page) and finally within this same function i submit the form,to run a query and use resultset to populate form.
After populating form on clicking the save button the form is submitted a second time to
insert form fields into database.
How do i retain all form fields(data) after clicking the save button to insert in database,because i found out after a successful insert and showing same page to allow user to click on nextPage button.The form fields are cleared and drop down goes to default selected option.
Please help!!
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
Hi Gabriel Fox ,

First of all store all the form element values in some variables while reading them from request object or you can reset them in the request attribute itself by saying request.setAttribute.
For list or drop down store the index number.
Once you are back on the same page, read the values from the attributes and in body onload reset all the form elements with the new values.
e.g if a form element name is
<input type="text" name="test" >
read it's value in jsp by
and then set in the attribute
in onbody load read it like
String test = request.getAttribute("test");
and in the javascript say
var test = "<%=test %>";
document.forms[0].test.value = test;
But for the drop down or the list box you have to store the selectedIndex value.
try this and good luck.

SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
Thanks Vijay ,what i did was to get the form
fields back from the request object using
request.getParameter("name"),since the form is
submitted to itself via the controller.Then stick in form like this:
<input type="name" value="<%=request.getParameter("name")%>">
I agree. Here's the link:
subject: Problem retaining form field after submission
It's not a secret anymore!