aspose file tools*
The moose likes Struts and the fly likes access iterated struts tag in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "access iterated struts tag in javascript" Watch "access iterated struts tag in javascript" New topic
Author

access iterated struts tag in javascript

M Murthy
Ranch Hand

Joined: Nov 20, 2004
Posts: 33
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>


Sindhu Murthy<br />SCJP 1.4<br />SCBCD
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

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!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
M Murthy
Ranch Hand

Joined: Nov 20, 2004
Posts: 33
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

Joined: Nov 20, 2004
Posts: 33
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

Joined: Feb 25, 2006
Posts: 4
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access iterated struts tag in javascript