Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

styleID attribute

 
Vani Bandargal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I know the purpose of styleID attribute(Ex:in html:text). It's basically to give the element an ID attribute since the name attribute is overloaded.

But I am having problem in assigning id attribute for a element which has indexed/nested property.

<html:text indexed="true" name="riskResults" property="riskFromDate" size="10" maxlength="10" styleClass="AdmTextBox" />

I have to specify name attribute because "rishResults" is a innerbean for the outerone, like this

public class LymeSupplementForm extends ValidatorActionForm {
private String firstName;
private List riskList = new ArrayList()
public RiskResults getRiskResults(int index)
{
while(index >= riskList.size()){
riskList.add(new RiskResults());
}
return (RiskResults)riskList.get(index);
}

public void setRiskResults(int index,RiskResults risk)
{
riskList.set(index,risk);
}
}

in my javascript, I do something like this
var inDate = trim(document.getElementById('riskResults['+ 0+ '].riskFromDate').value);

this is where I get the problem. It works fine in IE but not in Mozilla. IE automatically treates the name attribute as ID but for Mozilla, I had to explicilty specify ID attribute.
I tried adding styleID attribute but still no,luck

Can someone please help me?
[ March 27, 2007: Message edited by: Vani D Bandargal ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask questions on the Struts tags in the Struts forum. This post has been moved there for you.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The indexed attribute of the <html:text> tag causes the name attribute of the rendered HTML page to be indexed. However, it does nothing with the styleId attribute except pass it through as-is to create the id attribute in the rendered HTML. If you want an indexed value for the id, you will have to build it yourself using a scriptlet.

There is another way to do it, though. I'd suggest using the JavaScript getElementsByName function. This function always returns an array, even if there is only one element with the specified name. Something like the following would work:


[ March 27, 2007: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic