Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Passing arguments to 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 "Passing arguments to javascript..." Watch "Passing arguments to javascript..." New topic
Author

Passing arguments to javascript...

Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
Hello all,

(This is my first project in Struts so expect many questions ).
How can I pass arguments to JS functions using Struts tags ? Obviously something like will not work.
Also, I tried using plain jsp

but still didn't work (it just called my function with string <%=my_var%> as an argument .

Thanks a lot !
Dan
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
When you view the source of the outputted html page, what is displayed?
Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
Well, as I said ... the code looks something like
There are no typos or anything...

Thanks a lot,
Dan
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, when providing code for an onclick event, you do not use the prefix "javascript:". Just write JavaScript code.

Secondly, you can use a run-time expression in the attribute of a Struts tag, but the rule is "all or nothing", meaning that the entire attribute must be a run-time expression, or else no part of it can be a run-time expression. The following should work:

on click='<%="my_function('"+my_var+"')"%>'


Merrill
Consultant, Sima Solutions
Daniel Platon
Ranch Hand

Joined: Oct 10, 2005
Posts: 42
Thanks a lot for your replies. It should work just fine

Dan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing arguments to javascript...
 
Similar Threads
javax.servlet.jsp. JspException: Cannot find message resources under key
Conditional assignment
How can I use hyper link when submit a form?
Cannot set parameter in HTML:Link
Websphere 6 not recognizing c:forEach