This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to Set value of text Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to Set value of text Box " Watch "How to Set value of text Box " New topic
Author

How to Set value of text Box

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270


Hi I am struggling with a problem I have a text box name amount in which user put amount in simple format like 100000
now my requirement is to change this 10000 in 100,000.00 format meaning I need I ',' after every 3 digit plue in the end .00 must be added into the digit. For this I tried lots of ways like java scipt, try to change it on my bean,sciptlet but it won't work(or may be I am not doing it correctly). Need help to change this digit on my jsp page ....

Thanks in advance

Kaustubh


No Kaustubh No Fun, Know Kaustubh Know Fun..
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30075
    
149

Kaustubh,
JavaScript seems like a good solution. What did you try? What error did you get?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270

Hi Jeanne actually I was trying some of my logic and some from the internet but in both cases it won't work for me I am not getting any error message because I don't know how to complie javascript code the only way i found to test it, is by alert message ...............


you can see my stupid code down here.....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There are at least four problems with your code:

1) You manipulate the value but never set it back to the input element.
2) You set the variable "x" to one inside the loop every iteration, so it will never equal three.
3) You set the variable "number" only to the current digit plus a comma, and then only when x == 3 (which will never happen).
4) This starts the counting-by-three operation at the beginning of the value--but that's not actually what you want, otherwise you might end up with "123,4.69".

Fix those problems first. Remember that your goal is to build a new value with all of the contents of the old value, but with an additional comma every three numbers.

This code is so short there's no reason to use alert boxes (or anything else for that matter)--work it through in your head, along with some paper and a pen or pencil.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(For what it's worth, a naive implementation clocks in at ~10 lines of code.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to Set value of text Box
 
Similar Threads
Problem using Spring bind
Help in javascript
html:text not supporting non engilsh characters
Getting a Four Digit Date from SQL call
Need suggestions and help for my scenario in struts