This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts and Dynamic Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and Dynamic Javascript" Watch "Struts and Dynamic Javascript" New topic
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts and Dynamic Javascript
 
Similar Threads
How to use javascript in Struts
Struts 1: How to access Struts form data in JavaScript
struts tag for calender
Struts javascript validation
Struts2JQuery ShowCase application