| Author |
assigning javascript function's result to text box value when loading
|
Raji ram
Greenhorn
Joined: Oct 14, 2003
Posts: 19
|
|
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.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
|
Can't you just use JSP to format the code when you are writing it to the page?
|
 |
Raji ram
Greenhorn
Joined: Oct 14, 2003
Posts: 19
|
|
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.
|
 |
Tom Blough
Ranch Hand
Joined: Jul 31, 2003
Posts: 263
|
|
[ December 02, 2003: Message edited by: Tom Blough ]
|
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
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
Joined: Oct 14, 2003
Posts: 19
|
|
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
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
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.
|
 |
gino mendoza
Greenhorn
Joined: Jul 12, 2002
Posts: 20
|
|
Eric/anyone - Do yo have some sample code to format amounts to be displayed using JSP? Thanks.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
|
gino start a new topic in the jsp forum..
|
 |
 |
|
|
subject: assigning javascript function's result to text box value when loading
|
|
|