Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass parameter dynamically in Javascript in html:select

 
vicky kumar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the indexId="loopIndex" attribute of the logic iterate tag in conjunction with the "handleSwapTypeChange(<%= loopIndex %> ".
 
vicky kumar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic