aspose file tools*
The moose likes Struts and the fly likes Pass parameter dynamically in Javascript in html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pass parameter dynamically in Javascript in html:select" Watch "Pass parameter dynamically in Javascript in html:select" New topic
Author

Pass parameter dynamically in Javascript in html:select

vicky kumar
Ranch Hand

Joined: Dec 13, 2002
Posts: 55
Hi,
I have the following peace of code. How can I pass the current rowNum in iterate tage to onchange="handleSwapTypeChange(??)".

<logic:iterate id="myBean" name="myForm" property="myList">
<tr bgcolor=#FFFFFF>
<td valign="top">
<html:select name="myBean" property="myProp" indexed="true" onchange="handleSwapTypeChange(???)" >
<html ptions collection="myList" property="value" labelProperty="label" />
</html:select>
</td>
</tr>
</logic:iterate>
Matthew Marquand
Ranch Hand

Joined: Dec 19, 2002
Posts: 32
Use the indexId="loopIndex" attribute of the logic iterate tag in conjunction with the "handleSwapTypeChange(<%= loopIndex %> ".
vicky kumar
Ranch Hand

Joined: Dec 13, 2002
Posts: 55
Hi Mathew,
"handleSwapTypeChange(<%= loopIndex %> ".

prints the string as it is inside the html:select tag. So I am not getting loopIndex value printed.

Are you sure you have tested this way. I have tried several ways to spit out scriplets inside struts-tags, but in vain.

Could someone help. I have spent a lot of time figuring this out.

Cheers
Vicky
Matthew Marquand
Ranch Hand

Joined: Dec 19, 2002
Posts: 32
Sorry about my previous post; I was posting from memory.

It looks like we build complicated javascript invocations in a scriptlet:

<%
String onChangeJS = "handleSwapTypeChange('" + loopIndex + "');";
%>

and then on your select:

onchange="<%= onChangeJS %>"
vicky kumar
Ranch Hand

Joined: Dec 13, 2002
Posts: 55
Thanks Mathew.
Yes that's the only it works. I tried it before getting your reply. But your post confirms that this is the only way of achieving it. Wondering if struts-el offers spme solution without scriplets.

Thanks again
Cheers
Vicky
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass parameter dynamically in Javascript in html:select
 
Similar Threads
Struts 1 :how to display collection
retrieve value of a field
problem with nested <logic:iterate>
getting 2D array view in jsp from actionform properties
pass <bean:write> to a function