"RESTREPO, ALEXANDER G [Non-Pharmacia/1000]" wrote:

> Stephan:

(i thought i'd answer and then maybe stephen'll correct my code ;-)

> I have 2 more questions.

> QUESTION 1:
> I have created a select object with
> 4 options. How can I select the 3rd
> option by value?

 public org.apache.ecs.html.Select selectOption(
                    org.apache.ecs.html.Select select,
                    String value)
  {
  if (value!=null && select!=null)
  {
   for (Enumeration en=select.elements();en.hasMoreElements();)
   {
    Object next=en.nextElement();
    if (next instanceof org.apache.ecs.html.Option)
    {
     org.apache.ecs.html.Option opt =(org.apache.ecs.html.Option) next;
     if (opt.getAttribute("value").equals(value))
     {
       opt.setSelected(true);
     } else {
      opt.setSelected(false);
     }
    }
   }
  }
  return select;
 }


> For example, is there a way to do the following:
> Select mySelect = new Select("Test");
> Option option1               =  new Option("Option 1");
> Option option2               =  new Option("Option 2");
> Option option3               =  new Option("Option 3");
> Option option4               =  new Option("Option 4");
> option1.addElement("HELLO1");
> option2.addElement("HELLO2");
> option3.addElement("HELLO3");
> option4.addElement("HELLO4");
> option5.addElement("HELLO5");
> mySelect.addElement(option1);
> mySelect.addElement(option2);
> mySelect.addElement(option3);
> mySelect.addElement(option4);
>
> mySelect.selectElementByValue("Option 3");<----------------HOW CAN I DO
> THIS?
>
> QUESTION 2:
> Is there a way to determine the number of options in a Select object?

take the last code example, and shove a counting integer in the loop.

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to