Thank you very very much!! It works perfect !!!

Julie




"Steve Armstrong" <[EMAIL PROTECTED]>
08/07/03 10:25 PM
Please respond to "Struts Users Mailing List"

 
        To:     "Struts Users Mailing List" <[EMAIL PROTECTED]>
        cc: 
        Subject:        RE: how to pass a jsp variable to a javascript function


Howdy,

There are definitely a number of funky things in your code example.  I'm 
not
exactly sure what you're trying to do since your onchange attribute is
calling a JavaScript function called "projectChange" which I don't see
anywhere, but here are a couple of things to look out for:

1.  I don't believe you can use a JSP expression inside some JavaScript
code, but someone can certainly correct me if I'm wrong.  What I have done
in the past is use a <bean:write> tag, so you should be able to do 
something
like:

<bean:define id="tmpIndex" value="23"/>

<script language="JavaScript" type="text/javascript">
  var y<bean:write name="tmpIndex"/> = <bean:write name="tmpIndex"/>;
</script>

if you *really* want to do that.

2. However, your question was "how do I pass a JSP variable to a 
Javascript
function" and it looks like this is what you are attempting to do with the
next part of your code:

<nested:select property="projectCodeId"
onchange="projectChange(y<%=tmpIndex%>)">

For this to work correctly, your JSP expression needs to be the entire 
value
for the onchange attribute (i.e., you can't embed a JSP expression into 
the
middle of an attribute value).  Thus, assuming you have a JavaScript
function named "projectChange" defined, and you really want to pass in a
JavaScript variable to this function as opposed to say, the Integer value
itself, then you should be able to say something like:

<nested:select property="projectCodeId" onchange='<%= "projectChange(y" +
tmpIndex +")" %>'>

3. But, rather than setting a JavaScript variable inside a nested:iterate
and then trying to pass this variable into "projectChange" it would seem 
to
be much simpler to simply pass in the value itself.  In other words,
something like:

<nested:iterate property="projectList" id="pro" indexId="proIdx">
  <nested:select property="projectCodeId" onchange='<%= "projectChange(" +
proIdx +")" %>'>

I haven't tested the above, but if I haven't missed any syntactic sugar, 
it
should work.

Cheers,
-Steve

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 07, 2003 5:30 PM
To: Struts Users Mailing List
Subject: Re: how to pass a jsp variable to a javascript function


I don't have javascript errors, the problem is  <%=tmpIndex%> can't be
translated into 0,1,2,.....
in javascript,  only the String"<%=tmpIndex%>".




Adam Hardy <[EMAIL PROTECTED]>
08/07/03 04:32 PM
Please respond to "Struts Users Mailing List"


        To:     Struts Users Mailing List <[EMAIL PROTECTED]>
        cc:
        Subject:        Re: how to pass a jsp variable to a javascript
function


Hi Julie,
what do you get as a result of that iterate? It looks correct. Do you
have javascript errors?

Adam
[EMAIL PROTECTED] wrote:
> Hi All,
>
> Can anyone suggest how to pass a jsp variable to a javascript function
> correctly? It is in a nested:iterate block that has an
indexId="tmpIndex".
>  what I would like to do is to have the 'y<%=tmpIndex%>' variable pass
> into my JavaScript function.It seems like the server side <%=tmpIndex%>
> variable can not be translated into the client side script function.
>
>
> Here is my code:
>
> <nested:iterate property="projectList" id="pro" indexId="proIdx">
> <bean:define id="tmpIndex" value="<%=
> String.valueOf(proIdx.intValue())%>"/>
> <script language='JavaScript'>
>                 var y<%=tmpIndex%>=<%=tmpIndex%>;
>                 </script>
> <nested:select property="projectCodeId" onchange="
projectChange(y<%=tmpIndex%>)">
> <nested:optionsCollection property="../projectCodeList"/>
>                                         </nested:select>
> </nested:iterate>
>
> any suggestions?
>
>
> Very Appreciated.
>
> Julie
>
> = = = = = = = = = == = = = = = == = = = = = = = == = = = = = == = = = =
> This transmittal and any attachments may contain confidential,
privileged or sensitive information and is solely for the use of the
intended recipient. If you are not intended recipient, you are hereby
notified that you have received this transmittal and any such attachments
in error and any review, dissemination, distribution or copying thereof is
strictly prohibited. If you have received this transmittal and any
attachments in error please notify the sender and immediately destroy the
message and all its attachments. Any opinions herein expressed may be
those of the author and not necessarily of Mizuho Corporate Bank, Ltd (the
"Bank"). The Bank accepts no responsibility for the accuracy or
completeness of any information herein contained.
> = = = = = = = = = == = = = = = == = = = = = = = == = = = = = == = = = =
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to