• Post Reply 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

assigning javascript function's result to text box value when loading

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it possible to call a javascript function when initializing a value to a text box.
I have a jsp page that has amounts displayed.
I have a java variable amount to be displayed in the text box.
<% String amount = 1000.00; %>
<input type="text" value="<%= amount %>" >
But I want to format the amount when displaying by calling a javascript function some thing like this
<input type="text" value="javascript:formatAmount('<%= amount %>')" >
but obviously, this doesn't work.
I guess an alternate way is to call a method on body onload to populate all the values. But i have a lot of fields that passing all of them as parameter to a function is impossible.
Can you please let me know of a better way?
Thanks,
Raji.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you just use JSP to format the code when you are writing it to the page?
 
Raji ram
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. That is what I am thinking of if I have no way to do through javascript.
So, do you think there is no way to do this through javascript.
Thanks Eric,
Raji.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ December 02, 2003: Message edited by: Tom Blough ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doing it with JavaScript will slow down the page loading time and can be jerky depending on how the browser will run the code. Doing it with JSP will be seamless.
I personnaly would not do anything with JavaScript if it can be handled with a server side code. That is what I do when I code in ASP or .NET.
Eric
 
Raji ram
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tom, for letting me know how to do this with Javascript.
Eric,Thanks for the suggestion to do this in JSP itself.
Eric,I was just looking at your website.
I am amazed that you offer coding help for free!!!
How do you manage to do that? How do you get time to help others?
I will do this in JSP itself. But, it is good to know that it can be done thro' javascript too.
Thanks,
Raji.
[ December 03, 2003: Message edited by: Raji ram ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I help on small projects, nothing big. People usually send me things in the mail for my help. Good way to get stuff from other places.
I basically do it for adding stuff to my website/resume.
You can loop through all the elements in the form quickly and convert the information. If all the fields are the need the conversion then you do not have to worry about checking attributes.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric/anyone -
Do yo have some sample code to format amounts to be displayed using JSP?
Thanks.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gino start a new topic in the jsp forum..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic