+ Start a Discussion

Problem with populating selectlist options using javascript


Hi everybody,
I 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.
I have highlighted the line where iam getting the problem.
<apex:page >
<script> window.onload = list1;
function list1()
var list = document.getElementById('{!$Component.listchosen}')
for(var i=0;i<10;i++)
list.add(new Option('xxx','xxx'));
<apex:outputPanel id="result"> <apex:form >
<b>Please select :</b>
<apex:selectList id="listchosen" multiselect="false" size="1"> </apex:selectList>



When you use a apex:selectList element, the ID is mangled by Salesforce. You need to change the line as follows:



var list = document.getElementById('{!$Component.listchosen}')




Thanks for your reply, i made the change but still its not working somehow, I highlighted the line where i think iam getting the problem.



Thank you.