Solved

Form text box variable not holding value of what user typed in

Posted on 2006-06-28
13
356 Views
Last Modified: 2012-05-05
Hello and how is it? I am trying to hold my user's input values in my JSP page. This is my code:

String myName = null, msg ;
    myName = request.getParameter ("TXTName") ;
    if (myName == null){
        myName = (String) application.getAttribute("TXTName") ;
    }
    if (myName == null){
       
    }else {
        application.setAttribute("TXTName", myName) ;
    }

In the index.jsp page.

Then also inside the index.jsp page I have this

<td><font>Name:</font></td>
                 <td><input type="Text" name="TXTName" value="<%=request.getParameter("TXTName")%>"></td>

Then if a user clicks on my tree view control the page reloads. However, the TXTName value goes back to Null everytime. What am I missing?

Thanks C
0
Comment
Question by:Corey_819
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 
LVL 3

Expert Comment

by:runa_paathak
ID: 17007138
Try changing this:

<input type="Text" name="TXTName" value="<%=request.getParameter("TXTName")%>">

to

<input type="Text" name="TXTName" value="<%=myName%>">
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17008744
Thanks for the suggestion, but for some reason it keeps going to back null when I click on my tree view link. So basically when the page reloads he TXTName is not retaining its value it just goes back to the myName Null. Thoughts??

0
 
LVL 3

Expert Comment

by:runa_paathak
ID: 17008856
The change that I suggested didn't work?

Is it actually displaying the string "null" in the text box or do you mean the text box is empty?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:runa_paathak
ID: 17008888
I think this is the reason:

The first time your page loads request.getParameter("TXTName") returns null. So, in your code below

 if (myName == null){
        myName = (String) application.getAttribute("TXTName") ;
 }
 
if (myName == null){
   
 }else {
       application.setAttribute("TXTName", myName) ;
 }

the first if block will be executed. Here, you are trying to get the value from the application object. But the first time around, even this will return null!

Then the else part of the next if is executed i.e., null is put on the application object. In effect, your myName will always be null.
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17009364
I am sorry I am still really new to JSP. So shoudl I only do a getParameter is it is not null or how shoudl my code here look. And by the way the application object shoudl be the session. Sorry a typo. :)
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17012200
I actually figured a way to do this with Java Script, but for some reason when the page reloads the check boxes I checked are disapearing. Any ideas why that is happening?

0
 
LVL 3

Accepted Solution

by:
runa_paathak earned 70 total points
ID: 17015843
Do something like this:

<% String checked = (request.getParameter("checkboxname") == null)? "":"CHECKED"; %>

and  for the checkbox:

<INPUT TYPE=CHECKBOX NAME="checkboxname" <%= checked %>>Checkbox<BR>
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17017318
Thanks runa_paathak, but still when I click on another parent node to expand the tree the checked checkbox goes un checked again. :)
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17018616
Okay I have the Form's text boxes holding theri values. However, one more question. How can I get the form values to be blank and not null when the page loades up?

0
 
LVL 1

Author Comment

by:Corey_819
ID: 17018710
Forget last post. I figured out my issue. :)
However, I am still not getting the check boxes checked;
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17018794
I am sorry real quick question how would I hold a drop down box value?
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17020085
I apologize again nevermide on the drop downs I have those working. Still wrestling with the check boxes?
0
 
LVL 1

Author Comment

by:Corey_819
ID: 17020407
Thanks man you gave me ideas and your CHECKED solution helped me out. :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 248
AlarmClock Challenge 35 157
Spring MVC - sending raw charset to backend 3 270
if statement not resolving in my code 5 56
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question