| Author |
Struts and Dynamic Javascript
|
vicky kumar
Ranch Hand
Joined: Dec 13, 2002
Posts: 55
|
|
Hi, I'm using struts 1.0. I need to generate Javascript dynamically. It is not for validation. On onChange event of select-box I need to change value of a textfield. And these values are known until run time. Can someone suggest me best way to achieve it. Should I have a method in my action form that generates a string of javascript. Is this efficient though ? Do let me know some other strategies or ideas. Would really appreciate that. Thanks Vicky
|
 |
Balan Raj
Ranch Hand
Joined: Aug 26, 2003
Posts: 74
|
|
If you know the values at run time why dont you use a combination of JS & scriplet ? You could do something like Maybe u can populate this at the end of the page ?
|
 |
vicky kumar
Ranch Hand
Joined: Dec 13, 2002
Posts: 55
|
|
I am able to generate javascript through a method (say getMyJs()) in my ActionForm. But I am haing weird problem. For example: to generate aleart ('I am here') I use the following java code: StringBuffer buff = new StriingBuffer() ... buff.appen("alert("' I am here'"); All I get in resultant JSP code (when I see view source) is '. So my alert looks like this alert('I am here' ; and this fails, as Javascript is unable to identify it. Does any have any idea / experience on how to pring Single Quote (') in Javascript through Java code (inside my struts action form). I have already spent a whole day in this seemingly simple problem. Cheers Vicky
|
 |
Balan Raj
Ranch Hand
Joined: Aug 26, 2003
Posts: 74
|
|
In case you haven't resolved it yet 1. Play around with single & double quotes.. JS accepts single quote 2. Use escape characters to achieve that [ September 28, 2004: Message edited by: Balan Ram ]
|
 |
 |
|
|
subject: Struts and Dynamic Javascript
|
|
|