• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

access iterated struts tag in javascript

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
rubbery bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic