+ Start a Discussion
kumar_devkumar_dev 

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.

 

 

Controller:
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++)
  {
 testList.add('Testing'+i);
  }
Iterations=testList.size();
 }
public void validating()
{
system.debug('select list number' +optionNumber);
options=testList.get(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;
passingSelectedValue(optionNumber);
list.add(new Option('{!options}','{!options}'));
 }
}
</script>
<apex:form >
 <apex:actionFunction name="passingSelectedValue" action="{!validating}" reRender="test"  >
    <apex:param name="optionNumber" assignTo="{!optionNumber}" value="" />
</apex:actionFunction>
<apex:outputPanel id="test">
    <apex:outputtext value="{!options}" id="idSearchGeneric"/>
</apex:outputPanel>
<select id="list" size="1" value="{!selectedValue}" >
<option value=''>--None--</option>
 </select>
 
</apex:form>
</apex:page>

 

Ispita_NavatarIspita_Navatar

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.