function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vanessa veronvanessa veron 

set value select List

Hello ...

I have a JS function to get the value of an outputText and present in selectOption.

But is not working.
Help me!

Thank you!

var animals = document.getElementById("{!$Component.theform.block01.minuteOP}");
    var animalsToFind = document.getElementById("{!$Component.theform.block01.minuteIP}");

    var len = animals.options.length;
    for(i = 0; i < len; i++)
    {

      if (animals.options[i].innerHTML == animalsToFind.value)
      {
         animals.selectedIndex = i;
         break;
      }     
    }

}

..........................

<apex:selectList size="1" value="{!minute}" id="minuteIP">
                 <apex:selectOption itemValue="00" itemLabel="00"/>
                 <apex:selectOption itemValue="10" itemLabel="10"/>
                 <apex:selectOption itemValue="20" itemLabel="20"/>
                 <apex:selectOption itemValue="30" itemLabel="30" />
                 <apex:selectOption itemValue="40" itemLabel="40"/>
                 <apex:selectOption itemValue="50" itemLabel="50"/>
    </apex:selectList>
    
    <apex:outputText value="{!$CurrentPage.parameters.minutePG2}" id="minuteOP" /><br />

@LaceySnr - Matt Lacey@LaceySnr - Matt Lacey
You're looping over the wrong element!

"animals" is the text field, not the select list, so "animals.options.length" would be undefined.