Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing arguments to javascript...

 
Daniel Platon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you view the source of the outputted html page, what is displayed?
 
Daniel Platon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as I said ... the code looks something like
There are no typos or anything...

Thanks a lot,
Dan
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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+"')"%>'
 
Daniel Platon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your replies. It should work just fine

Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic