Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need changes in JSP factorial program regarding to updation

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
I have made a simple JSP code to find factorial of number which is as below,
Now I want some changes in this.


When I type number is textbox and submit data, I get result but the data from textbox is removed,
what if I want to keep the entered data as previously !!

Also clear button is also not working how to code in jsp to clear the form ??

Please guide me as I am beginner.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
If you want to populate the field with the previous value, your code will have to put it there. That's what the value attribute is for. Only if the value is not null, of course.

Also clear button is also not working how to code in jsp to clear the form ?


What is the use case for having one in your form? Just because HTML forms support that concept, does not mean that it's a useful one.
 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
First of all thank you for reply sir.
I know that there is no meaning of retrieving those values in text box but as I am in learning phase, I want to know that how to do it.....
It would be better if explain me how to do it.
Thank you once again for your reply.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please drop the habit of quoting entire posts. Quoting is for extracting specific bits of a previous posts that your reply references. Otherwise it makes no sense, and you should use the "Post reply" button instead. Notice how I used quoting in my previous post?

I did not say there was no meaning in putting values in the text box. I said there probably is no point in having a "clear form" button. If the objective is to learn, then there are much more important things for you to learn - for example, to structure your web app in such a way that there are no scriptlets in JSPs.

As to putting previously used input value into the form fields, are you familiar with the value attribute of the <input> tag that I mentioned? If not, that's what you should get started with. Once you know what that is and how it works, it should not be hard to add it to your JSP and populate it with the previous value should there be one. If you get stuck, come back here, tell us what you've learned, and how you tried to apply that, and we'll try to get you going again.
 
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Ok first of all you have done some unnecessary things (You are in learning phase it is adjustable no problem :) ). If you need to show your value in text box you can do as below

<% long nm1 = Integer.parseInt(request.getParameter("num1")); %>

place this code first of your .jsp page

Then change your input field as

<input type="text" name="num1" onkeypress="return num(event)" value="<%=nm1 %>">

Please check with this.

 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thank you sir,
It worked as well as I understood...
Thank you so much.


I havve another doubt. Can I ask ?
 
Niju Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Sure please ask...:)
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You're welcome to ask as many questions as you like. But please try and keep it to one issue per thread.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic