Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing a textfield value

Status
Not open for further replies.

keinloffel

Programmer
Mar 24, 2003
11
US
I have a JSP page in which I have:

o One drop down box (Uses SELECT) - Called WorkType
o One Text Field. - Called Description


I also have a JavaBean in which I have instance variables for both WorkType and Description.

Every Time I change the worktype, the page refreshes. The problem I am facing is that I am not able to store what is entered into the description box so that after I refresh, the same description turns up again.

So, if i choose worktype1 and enter in the description: haha
Then if i change the worktype to worktype2, the page refreshes with
worktype = worktype2
description = blank

For every refresh I am able to store what worktype i have, in the bean. This is made much easier by the fact that it uses the SELECT keyword.


<OPTION SELECTED VALUE=&quot;<%= workTypes[x][0] %>&quot; > <%= workTypes[x][1] %> </OPTION>
<% sb.setWorkType( workTypes[x][0] ); %>
<% } else { %>
<OPTION VALUE=&quot;<%= workTypes[x][0] %>&quot;> <%= workTypes[x][1] %> </OPTION>

the setWorkType does the saving for me.

My problem is that I cannot do the same for description, so that the page remembers what the user wrote, EVEN IF they didnt hit submit. If they had hit submit, i would easily have used request.getParameter and got the description. But here the problem is the user never saves the description at all.

Here's the description line i have so far:

<TD class=&quot;main1&quot;><b>Description</b><br><TEXTAREA ROWS=1 COLS=30 NAME=&quot;description&quot; ><%= sb.stripTilde(loadDescription) %></TEXTAREA></TD>
<% } %>

I need to be able to somehow say, sb.setDescription like i did for worktype. But I cant pull out whats entered in the box.


Any suggestions???


Thanks!!!!!!
 
I don't understand your post. You say the page &quot;refreshes&quot;. That is ambiguous. You say you can’t use “request.getParameter”:

the problem is the user never saves the description

I don’t understand the use of the word “saves”?

Every Time I change the worktype, the page refreshes.

How does that happen? Post the “relevant” code that creates that behavior. (not your entire page). Alternatively if your site is public give us the Url so we can see the page directly.

Use precise technical descriptions or we cannot understand what you are saying. HTTP pages can be refreshed. Forms can be submitted, posted etc.

Based on the information you gave us we have no idea what is happening.

-pete
 
Alright. I'll try to make this clearer.

There is a textarea(description). Below it is a drop down box(worktype).

Lets say I type in something in the description.
Then I go to the drop down and change the value in there, to the second value in the drop down.
The way the drop down is set up, another developer used the onchange feature in it. So whenever the drop down value changes, the page is directed to the same page but with the drop down, being what the user just chose(this is what i meant by refresh.)

However, when this happens and we return to the page, the description now disappears and we lose whatever was written in the textarea.

My issue was that i wanted to be able to store the description in the bean, so that i could load the textarea when we were redirected to the page.

For that, in the jsp page I would need to say:

sb.setDescription(something). I don't know what to set something to, as I dont know how to extract what the user just entered in the textarea. Is that even possible?

Thanks. I hope thats clearer
 
Yes it is somewhat clearer but you did not &quot;post the relevant&quot; code that someone else developed that used the &quot;onchange&quot; event of the <select> element.

I have to guess what is happening based on the page is directed to the same page

I will guess that the developer is not submitting the form. If you change that code to submit the form your problem should be solved as you will now have access to the other form variable (the textarea). this of course assumes your page has a form and all the input elements are in the form.

does that help?
-pete
 
Thanks for your reply.
However I wouldnt like to have the form submitted. I know how to do it if the form was to be submitted. But here, the page is simply refreshed(redirected to same page) and i want to reload the same information that was entered previously. Its really weird because the previous developer came up with this refreshing code and so that makes it hard for me retrieve prior information.

Some of the relevant code:

----------
<TD class=&quot;main1&quot;>
<b>WorkType</b>

<SELECT name=&quot;worktype&quot; onchange=&quot;location.href='./timereporting3.jsp?all=<%= sb.getAllProjects() %>&worktype=' + document.entry.worktype.value + '&workphase=' + document.entry.workphase.value +'&worktype2=' + document.entry.worktype2.value &quot; >
<%
String[][] workTypes = sb.getWorkTypeList();
for (int x = 0; x < workTypes.length ; x++ ) {
if( workTypes[x][0].equals( loadWorkType )) { %>
<OPTION SELECTED VALUE=&quot;<%= workTypes[x][0] %>&quot; > <%= workTypes[x][1] %> </OPTION>
<% sb.setWorkType( workTypes[x][0] ); %>
<% } else { %>
<OPTION VALUE=&quot;<%= workTypes[x][0] %>&quot;> <%= workTypes[x][1] %> </OPTION>
<% } %>
<% } //End for next loop %>
</SELECT>
</TD>
----------
That was the drop down box.

And heres the text field.
-------------------
<TD class=&quot;main1&quot;><b>Description</b><br><TEXTAREA ROWS=1 COLS=30 NAME=&quot;description&quot; ><%= sb.stripTilde(loadDescription) %></TEXTAREA></TD>
---------------

Thanks for your help.
 
>> Its really weird

Yes it is, it might also be a bad design. Without having full requirements it is impossible to know for sure but what you posted looks pretty ugly. Let me ask a question.

So if a user changes what is in the <textarea> then selects something from the drop down combobox (<select> element) you are going to replace whatever they put into the <textarea> with whatever was previously in the <textarea>? And since you never submit the form how do you ever receive what is in the <textarea>?

-pete
 
Thats the issue. Receiving what was in the text area without ever submitting the form.

From our discussions it seems like that is not possible and I will have to revamp the design of the whole page.

Darn it. I wish the developer hadn't made it this way.
 
Hold on now. It might be entirly possible by altering what is in the <select> elements &quot;onchange&quot; attribute.

You should be able to include the <textarea> value in the same fashion the other values are included in the QueryString. Now there is a limit on QueryString size but i think it is like 4k or something so you might be alright.

Have you tried adding the <textarea> element value to the QueryString?

-pete
 
Thats Quite Brilliant. Thankyou very much. My problems seem resolved for the moment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top