Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Pass parameter dynamically in Javascript in html:select

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic