• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Set value of text Box

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaustubh,
JavaScript seems like a good solution. What did you try? What error did you get?
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(For what it's worth, a naive implementation clocks in at ~10 lines of code.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic