How to pass Element Name of Struts-form to Java-Script function??
843840Jun 16 2008 — edited Jun 16 2008Hi EveryOne,
I guess u can help me to find out the solution. I have created a jps say ABC.jsp using struts frame work.
the jsp is something like :
<html:form action="\someaction...."
<table>
<logic:iterate id="strArrBatchName" name="batchScheduleForm" property="strArrBatchName">
<tr>
<td>
<html:text name="BatchScheduleForm" property="strArrBatchName" value="<%=strArrBatchName.toString()%>">
</html:text>
<td>
<html:text name="BatchScheduleForm" property="strArrScheduledDate"value="">
</html:text>
<html:link href="javascript:cal1.popup();">Calendar</html:link>
</td>
</tr>
</logic:iterate>
</table>
</html:form>
<script language="javascript">
var cal1 = new calendar1(document.forms[0].elements['3']);
</script>
Here the javascript function calendar1() is called when user click the link "Calendar" .Also this function set some value to field "
<html:text name="BatchScheduleForm" property="strArrScheduledDate"value=""> "
Here is problem is in the calendar1() function i have hardcoded the forms and elements value.It means whenever user clicks the ANY link "Calendar" (there will be one Calendar link in each row ) it will AlWAYS set some value in the field "document.forms[0].elements['3']" . But this should be not happen .It should set value of those field for which Calendar link is activated.
Therefore how can we get the element id or name of field in struts that can be passed dynamically into the javaScript function. In other words how should i define the Function Calendar1() argument so that it will work correctly.
Suggestions are highly welcomed.