+ Start a Discussion

Pleasee help, Populating selectlist options using onload javascript function from controller

Hello Friends,

According to my requirment i need to update selectlist with more than 1000 items from controller arraylist,which is not possible in Visuaforce page as we should not exceed more than 1000 at a time, so I am trying to populate selectlist options using  javascript onload function and using apex:actionFunction to invoke a method in controller to update selectoptions ,But somehow the selectlist is not being updated after each iteration in javascript.

Please look at the sample code that i have written and suggest me any changes to make it work.



public class commentsController {
public Integer Iterations{get;set;}
public list<string> testList{get;set;}
public Integer optionNumber{get;set;}
public string options {get;set;}
public string selectedValue{get;set;}
public commentsController(ApexPages.StandardController stdController)
testList= new list<string>(); 
for(integer i=0;i<50;i++)
public void validating()
system.debug('select list number' +optionNumber);
VF page code:
<apex:page id="commentspage"  standardController="opportunity" extensions="commentsController">
 <script language="Javascript">
 window.onload = CheckCategories;
function CheckCategories() {
var list=document.getElementById('list');
for(var i=0;i<{!Iterations};i++){
var optionNumber=i;
list.add(new Option('{!options}','{!options}'));
<apex:form >
 <apex:actionFunction name="passingSelectedValue" action="{!validating}" reRender="test"  >
    <apex:param name="optionNumber" assignTo="{!optionNumber}" value="" />
<apex:outputPanel id="test">
    <apex:outputtext value="{!options}" id="idSearchGeneric"/>
<select id="list" size="1" value="{!selectedValue}" >
<option value=''>--None--</option>



Try using the javascript API route for fetching data and use javascriting for populating your select list as in your case you have to handle huge data.

Hope this helps.