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

DynaValidatorForm javascript issue

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my struts-config I have

form-bean name="dynamicArrayForm" type="...DynaValidatorForm >
<form-property name="access" type="forms.AccessRequestForm[]"/>
</form-bean>

In my jsp I have

<c:forEach var="access" items="${dynamicArrayForm.map.access}">
<tr><td><<c ut value="${access.requestedBy}"/></td>
..
<td><html:checkbox property="approve" indexed="true" name="access" oncli="chkApprove(this.form)"/>
</td>
<td><html:text property="reasonForRejection" indexed="true" name="access" value="test"/></td>

In my html I have

<input type="checkbox" name="access[0].approve" value="on" onclic="chkApprove(this.form)"></td>
<td><input type="text" name="access[0].reasonForRejection" value="test">
In my js I have

function chkApprove(formP)
{

alert(formP.access[0].reasonForRejection.value);

In my js function I get the error 'access.0' is null or not an object

Thank you for your time
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JavaScript, any time an element name contains characters such as "[" or "." that have meaning in JavaScript, you can't access the element by just naming it as in myForm.myProperty[0].foo. You have to be creative and think of a way to treat the name as a string. For example:

myForm.item("myProperty[0].foo")

or

document.getElementsByName("myProperty[0].foo")[0]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic