struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <>
Subject Re: [S2] Newbie Passing S2 variables to javascript functions
Date Fri, 27 Apr 2007 20:27:53 GMT
Roger Varley wrote:
> Hi
> Within a <s:iterator> tag I have the following statement <s:set
> name="indexValue" value="#status.index"/> (because status seems to
> disappear when the iterator exits) and I use the expression
> %{#indexValue} within other struts s: tags without a problem.
> I now need to pass this value to a javascript function i.e
> onclick="enableField(%{#indexValue})" but the browser complains about
> invalid syntax. How do I pass the value "indexValue" to a javascript
> function?

Without seeing the error and the JSP code that generated it, it's hard 
to tell you what's wrong. However, remember that Javascript runs on the 
client, after the page has been generated. View the page source to see 
what the syntax error is. In this case, it's probably the lack of quotes 
around the OGNL expression. It may also be that an in-line expression 
like that wont work.

Here's a couple of suggestions to try:

     ... onclick="enableField('%{#indexValue}')" ...
     ... onclick="%{'enableField(\'' + #indexValue + '\')'}" ...
     ... onclick="enableField('${indexValue}')" ...


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message