1Hi everybody,
2I am trying to populate selectlist options through onload javascript function, but some how this is not working. I have pasted the code below that iam working on, could any body please suggest any changes to make it working.
3<apex:page >
4<script> window.onload = list1;
5function list1()
6{
7var list=document.getElementById('listchosen');
8for(var i=0;i<10;i++)
9list.add(new Option('xxx','xxx'));
10}
11</script>
12<apex:outputPanel id="result"> <apex:form >
13<b>Please select :</b>
14<apex:selectList id="listchosen" multiselect="false" size="1"> </apex:selectList>
15</apex:form>
16</apex:outputPanel>
17</apex:page>
1<apex:selectList styleclass="Lista" value ="{!type1}" size="1">
2 <apex:selectOptions value="{!Types}"/>
3</apex:selectList>
4
5var e = document.getElementsByClassName("Lista")[0];
6var strUser = e.options[e.selectedIndex].value;
1<apex:form >
2<apex:outputLabel value="Type" />
3<br/>
4<apex:selectList id="Lista" value ="{!type1}" size="1">
5 <apex:selectOptions value="{!Types}"/>
6</apex:selectList>
7<br/>
8<div class="typesSection"></div>
9<apex:outputLabel value="First/Last Name" />
10<br/>
11<apex:inputText value="{!searchText}" id="searchText"></apex:inputText>
12<apex:commandButton value="change" onClick="change()"/>
13</apex:form>
14
15<script>
16 function change(Lista){
17
18 ss = document.getElementById(Lista).value;
19 alert(ss);
20 }
21</script>
1You have to modify your list1 method.
2
31. SFDC generated ids at run time for the apex tags. Please use correct Id of the apex:selectList.
4
52. You should add the Option to options list of the html element.
6
7
8
9Please check the below code -
10
11function list1()
12
13{
14
15var list=document.getElementById('j_id0:j_id2:listchosen');
16
17for(var i=0;i<10;i++)
18
19list.options.add(new Option(i,i));
20
21}