Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Passing arguments to javascript...

 
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
 
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
 
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
 
I want my playground back. Here, I'll give you this tiny ad for it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic