• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access iterated struts tag in javascript

 
M Murthy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,


How do I access a struts <html:hidden> tag in the javascript and
disable it when a user clicks on a particular row of data. Below is the JSP and javascript. The problem I am facing is that the hidden tag is
indexed and i need the syntax for accessing it. I have tried

document.form.getElementById('schds[0].price').disabled = true;

but it doesnt work. Please let me know if you have any suggestions.


<script>
function highlight(curItem, index)
{
if(curItem.className == "normal")
{
curItem.className = "highlight";
// access the html:hidden field here and set its disabled=false
}
else
{
curItem.className = "normal";
// access the html:hidden field here and set its disabled=true
}

}

</script>

<logic:iterate id="stocks" name="stocks" type="someVO" indexId="ctr">
<TR Class="normal" id=<%=stocks.getprice()%> STYLE="height:16px;" onchange='<%="highlight(this, " + ctr + ")"%>'
<html:hidden name="schds" indexed="true" value="<%=stocks.getPrice()%>"
property="price" />
<TD><%=stocks.getReportName()%></TD>
</TR>
</logic:iterate>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34851
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to accomplish by disabling the field? Normally disabling is used so the user can't edit it. But a user can't edit a hidden field anyway.

I'm not sure if the HTML spec even allows for having to text fields with the same name.

And welcome to JavaRanch!
 
M Murthy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for welcoming.

Regarding disabling the hidden field. All i am trying to do is capture the user click and some how pass that information to the action class. The requirement is not to use checkboxes, but highlight the entire row when a user clicks the first time and thus select it (deselect for the second click). So the approach i have taken is as follows: Right now the value of all the rows displayed is being passed to the action class through the dyna form. So when a user clicks on a row i am trying to set the disabled attibute to true and false when user clicks the second time. So i need to access the tag in the javascript.

Looking forward to any suggestions.
 
M Murthy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I did some trial and error coding and figured out a solution to my problem.
The syntax to access a iterated struts tag in javascript is as below:

1)Define a styleId="someName" in the iterated tag
2)Then in the javascript use this syntax

document.getElementById('formName').someName[index].disabled

I spent quite some time researching on javascript syntax for struts tags. Hope this will give a quick answer to others with similar problem.
 
Richard Berger
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M. Murphy -

Don't know if you are following this thread - but THANK YOU - your research helped me out asI had the exact same problem.

Thanks,
RB
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic