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
ankur khattriankur khattri 

Picklist value disable

disable value of the picklist if that value is selected.
Best Answer chosen by ankur khattri
mritzimritzi
Hi @ankur

I have made few changes to your code, and its workinh pretty fine.
please have a look

Apex:
public with sharing class Picklist 
{
    public String err{get;set;}
    //shortened variable names
    public String sC1{get;set;}
    public String sC2{get;set;}
    public String sC3{get;set;}
    public String sC4{get;set;}
    public String sC5{get;set;}
    public String sC6{get;set;}
    public String sC7{get;set;}
    public String sC8{get;set;}
    public String sC9{get;set;}
    public String sC10{get;set;}
    
    //changed getCountriesOptions to cOs
    public List<SelectOption> cOs;
    public boolean disable{get; set;}
    
    public Picklist(){
        //populated selecOption List in constructor
        cOs = new List<SelectOption>();
        cOs.add(new SelectOption('','-None-'));
        cOs.add(new SelectOption('INDIA','India'));
        cOs.add(new SelectOption('USA','USA'));
        cOs.add(new SelectOption('United Kingdom','UK'));
        cOs.add(new SelectOption('Germany','Germany'));
        cOs.add(new SelectOption('Ireland','Ireland'));
        cOs.add(new SelectOption('bangladesh','bangladesh'));
        cOs.add(new SelectOption('pakistan','pakistan'));
        cOs.add(new SelectOption('srilanka','srilanka'));
        cOs.add(new SelectOption('bhutan','bhutan'));
    }
     
    public List<SelectOption> getCountriesOptions() {
        //simply return already populated list
        return cOs;
    }
    //added new function, it is executed whenever selectList value is changed
    public void removeCountry() {
        Integer listSize = cOs.size();
        //excluded index 0 in loop as it holds null value
        for(Integer i=1;i<listSize;i++){
            if(cOs[i].getValue()==sC1 || cOs[i].getValue()==sC2 || cOs[i].getValue()==sC3 || cOs[i].getValue()==sC4 || cOs[i].getValue()==sC5 || cOs[i].getValue()==sC6 || cOs[i].getValue()==sC7 || cOs[i].getValue()==sC8 || cOs[i].getValue()==sC9 || cOs[i].getValue()==sC10){
                cos[i].setDisabled(true);
            }
            else if(cOs[i].getValue()!=sC1 && cOs[i].getValue()!=sC2 && cOs[i].getValue()!=sC3 && cOs[i].getValue()!=sC4 && cOs[i].getValue()!=sC5 && cOs[i].getValue()!=sC6 && cOs[i].getValue()!=sC7 && cOs[i].getValue()!=sC8 && cOs[i].getValue()!=sC9 && cOs[i].getValue()!=sC10){
                cos[i].setDisabled(false);
            }
        }
    }
    
}

VF Page
<apex:page controller="Picklist" sidebar="false" showheader="false"> 
    <apex:form >
    <h4>{!err}</h4>
    <apex:sectionHeader title="PickList Value Selection"/>
            <apex:PageBlock >
                <apex:pageBlockSection id="pbs1" collapsible="false" >
                    <apex:selectList value="{!sC1}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <!--added following line in each selectList to call apex method -->
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>    
                <apex:pageBlockSection id="pbs2" collapsible="false">
                    <apex:selectList value="{!sC2}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs3" collapsible="false">
                    <apex:selectList value="{!sC3}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs4" collapsible="false">
                    <apex:selectList value="{!sC4}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs5" collapsible="false">
                    <apex:selectList value="{!sC5}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs6" collapsible="false">
                    <apex:selectList value="{!sC6}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs7" collapsible="false">
                    <apex:selectList value="{!sC7}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs8" collapsible="false">
                    <apex:selectList value="{!sC8}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs9" collapsible="false">
                    <apex:selectList value="{!sC9}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs10" collapsible="false">
                    <apex:selectList value="{!sC10}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9"/>
                    </apex:selectList>
                </apex:pageBlockSection>   
            </apex:PageBlock>
  </apex:form>
  <!--
  <script href="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script>
      $(document).ready(function(){
          alert('hi');
          $('select').change(function(){
              var selectedCountry = $(this).val();
              alert(selectedCountry);
              $('select').each(function(){
                  if($(this).find('option').val()==selectedCountry){
                      $(this).find('option').attr('disabled','true');
                  }
              });
          }); 
      });
  </script>-->
</apex:page>



Hit like if it helped you  in anyways. Select it as Best answer it it solved your problem. Cheers

All Answers

sslodhi87sslodhi87
Hi Ankur,

Do you mean.. if we select any vaule than that value should removed from the pick-list so that it should not selected again?

If possible share the requirment or code that will help me to give the solution.

Thanks,
ankur khattriankur khattri
yep @ssiodhi87
ankur khattriankur khattri
i have 10 picklist with same values in it for eg opt1,opt2 so on......if in first picklist user choose opt1 then i should disable from the remaining 9 picklist field. 
ankur khattriankur khattri
heres my code
controller

public with sharing class Picklist 
{
    public String selectedCountry1{get;set;}
    public String selectedCountry2{get;set;}
    public String selectedCountry3{get;set;}
    public String selectedCountry4{get;set;}
    public String selectedCountry5{get;set;}
    public String selectedCountry6{get;set;}
    public String selectedCountry7{get;set;}
    public String selectedCountry8{get;set;}
    public String selectedCountry9{get;set;}
    public String selectedCountry10{get;set;}
    public List<SelectOption> getCountriesOptions = new List<SelectOption>();
    public boolean disable{get; set;} 
    public List<SelectOption> getCountriesOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        countryOptions.add(new SelectOption('','-None-'));
        countryOptions.add(new SelectOption('INDIA','India'));
        countryOptions.add(new SelectOption('USA','USA'));
        countryOptions.add(new SelectOption('United Kingdom','UK'));
        countryOptions.add(new SelectOption('Germany','Germany'));
        countryOptions.add(new SelectOption('Ireland','Ireland'));
        countryOptions.add(new SelectOption('bangladesh','bangladesh'));
        countryOptions.add(new SelectOption('pakistan','pakistan'));
        countryOptions.add(new SelectOption('srilanka','srilanka'));
        countryOptions.add(new SelectOption('bhutan','bhutan'));
 
        return countryOptions;
    }
    
    public Picklist()
    {
        
    }
    
}

VFPage

<apex:page controller="Picklist" sidebar="false"> 
    <apex:form >
    <apex:sectionHeader title="PickList Value Selection"/>
            <apex:PageBlock >
                <apex:pageBlockSection collapsible="false" >
                    <apex:selectList value="{!selectedCountry1}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>    
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry2}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry3}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry4}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry5}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry6}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry7}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry8}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry9}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!selectedCountry10}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>   
            </apex:PageBlock>
  </apex:form>
</apex:page>
sslodhi87sslodhi87
Hi Ankur,

There are two way to achieve the functionality one way using javascript and another way by apex.

I will help you how we can achiveve from apex controller.
public class DemoPicklist
{
	public String strPicklist1		{	get;set;	}
	public String strPicklist2		{	get;set;	}
	public String strPicklist3		{	get;set;	}
	public String strPicklist4		{	get;set;	}
	public String strPicklist5		{	get;set;	}
	public String strPicklist6		{	get;set;	}
	public String strPicklist7		{	get;set;	}
	public String strPicklist8		{	get;set;	}
	public String strPicklist9		{	get;set;	}
	public String strPicklist10		{	get;set;	}
	
	
	public List<SelectOption> getPicklistOptions()
	{
		List<SelectOption> options = new List<SelectOption>{new selectOption('none', 'none')};
		Schema.sObjectType sobject_type = Customobject__c.getSObjectType(); //grab the sobject that was passed
        Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
        Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
        List<Schema.PicklistEntry> pick_list_values = field_map.get('Customfield__c').getDescribe().getPickListValues(); //grab the list of picklist values for the passed field on the sobject
        for(Schema.PicklistEntry a : pick_list_values) 
        { 
			if(strPicklist1.indexOf(a.getValue()) != -1 || strPicklist2.indexOf(a.getValue()) != -1 ||strPicklist3.indexOf(a.getValue()) != -1 ||
			   strPicklist4.indexOf(a.getValue()) != -1 || strPicklist5.indexOf(a.getValue()) != -1 || strPicklist6.indexOf(a.getValue()) != -1 || 
			   strPicklist7.indexOf(a.getValue()) != -1 || strPicklist8.indexOf(a.getValue()) != -1 || strPicklist9.indexOf(a.getValue()) != -1 ||
			   strPicklist10.indexOf(a.getValue()) != -1 ) continue;
			   
			options.put(new selectOption(a.getValue(), a.getLabel()));
        }
		
		return options;
	}
}


<apex:page controller="DemoPicklist">
	<apex:form>
		<apex:actionfunction name="updatepicklist" rerender="pd"/>
		<apex:pageblock id="pd">
			<apex:selectList value="{!strPicklist1}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist2}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist3}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist4}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist5}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist6}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist7}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist8}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist9}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist10}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
		</apex:pageblock>
	</apex:form>
</apex:page>

Please check this code and let me know if this help.

Thanks
 
ankur khattriankur khattri
@ssiodhi87 thanks.but m not using any custom object how to do it..thanks
sslodhi87sslodhi87
Hi Ankur,

I have updated the code please check this
public class DemoPicklist
{
	public String strPicklist1		{	get;set;	}
	public String strPicklist2		{	get;set;	}
	public String strPicklist3		{	get;set;	}
	public String strPicklist4		{	get;set;	}
	public String strPicklist5		{	get;set;	}
	public String strPicklist6		{	get;set;	}
	public String strPicklist7		{	get;set;	}
	public String strPicklist8		{	get;set;	}
	public String strPicklist9		{	get;set;	}
	public String strPicklist10		{	get;set;	}
	
	
	public List<SelectOption> getPicklistOptions()
	{
		
        for(SelectOption a : getCountriesOptions) 
        { 
			if(strPicklist1.indexOf(a.getValue()) != -1 || strPicklist2.indexOf(a.getValue()) != -1 ||strPicklist3.indexOf(a.getValue()) != -1 ||
			   strPicklist4.indexOf(a.getValue()) != -1 || strPicklist5.indexOf(a.getValue()) != -1 || strPicklist6.indexOf(a.getValue()) != -1 || 
			   strPicklist7.indexOf(a.getValue()) != -1 || strPicklist8.indexOf(a.getValue()) != -1 || strPicklist9.indexOf(a.getValue()) != -1 ||
			   strPicklist10.indexOf(a.getValue()) != -1 ) continue;
			   
			options.put(new selectOption(a.getValue(), a.getLabel()));
        }
		
		return options;
	}
	
	private List<SelectOption> getCountriesOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        countryOptions.add(new SelectOption('','-None-'));
        countryOptions.add(new SelectOption('INDIA','India'));
        countryOptions.add(new SelectOption('USA','USA'));
        countryOptions.add(new SelectOption('United Kingdom','UK'));
        countryOptions.add(new SelectOption('Germany','Germany'));
        countryOptions.add(new SelectOption('Ireland','Ireland'));
        countryOptions.add(new SelectOption('bangladesh','bangladesh'));
        countryOptions.add(new SelectOption('pakistan','pakistan'));
        countryOptions.add(new SelectOption('srilanka','srilanka'));
        countryOptions.add(new SelectOption('bhutan','bhutan'));
 
        return countryOptions;
    }
}


<apex:page controller="DemoPicklist">
	<apex:form>
		<apex:actionfunction name="updatepicklist" rerender="pd"/>
		<apex:pageblock id="pd">
			<apex:selectList value="{!strPicklist1}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist2}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist3}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist4}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist5}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist6}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist7}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist8}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist9}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
			<apex:selectList value="{!strPicklist10}" multiselect="false" size="1" onchange="updatepicklist();">
				<apex:selectOptions value="{!PicklistOptions}" />
			</apex:selectList>
		</apex:pageblock>
	</apex:form>
</apex:page>

Thanks
ankur khattriankur khattri
ERROR:-
controller:-Save error: Variable does not exist: getCountriesOptions
page:-Save error: Unknown property 'Picklist.strPicklist1'
 
sslodhi87sslodhi87
Please replace the page as well.
 
sslodhi87sslodhi87
does that work Ankur?
ankur khattriankur khattri
no it is not working
 
sslodhi87sslodhi87
did you replace the page and controller code?
 
ankur khattriankur khattri
yup
sslodhi87sslodhi87
now what issue you are facing?
ankur khattriankur khattri
Multiple annotations found at this line:
    - Save error: Unknown property 
     'DemoPicklist.PicklistOptions'
    - Save error: Unknown property 'DemoPicklist.strPicklist1'


Save error: Variable does not exist: getCountriesOptions
sslodhi87sslodhi87
change the controller of the page... use your controller name

or can you please share your controller and page code here
 
ankur khattriankur khattri
<apex:page controller="Picklist" sidebar="false"> 
    <apex:form >
    <apex:sectionHeader title="PickList Value Selection"/>       
            <apex:PageBlock >
                <apex:pageBlockSection collapsible="false" >
                    <apex:selectList value="{!strPicklist1}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>    
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist2}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist3}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist4}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist5}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist6}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist7}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist8}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist9}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection collapsible="false">
                    <apex:selectList value="{!strPicklist10}" multiselect="false" size="1">
                        <apex:selectOptions value="{!PicklistOptions}" />
                    </apex:selectList>
                </apex:pageBlockSection>   
            </apex:PageBlock>
  </apex:form>
</apex:page>
ankur khattriankur khattri
public class Picklist
{
    public String strPicklist1    {get;set;}
    public String strPicklist2    {get;set;}
    public String strPicklist3    {get;set;}
    public String strPicklist4    {get;set;}
    public String strPicklist5    {get;set;}
    public String strPicklist6    {get;set;}
    public String strPicklist7    {get;set;}
    public String strPicklist8    {get;set;}
    public String strPicklist9    {get;set;}
    public String strPicklist10    {get;set;}
    
    
    public List<SelectOption> getPicklistOptions()
    {
        
        for(SelectOption a : getCountriesOptions) 
        { 
            if(strPicklist1.indexOf(a.getValue()) != -1 || strPicklist2.indexOf(a.getValue()) != -1 ||strPicklist3.indexOf(a.getValue()) != -1 ||
               strPicklist4.indexOf(a.getValue()) != -1 || strPicklist5.indexOf(a.getValue()) != -1 || strPicklist6.indexOf(a.getValue()) != -1 || 
               strPicklist7.indexOf(a.getValue()) != -1 || strPicklist8.indexOf(a.getValue()) != -1 || strPicklist9.indexOf(a.getValue()) != -1 ||
               strPicklist10.indexOf(a.getValue()) != -1 ) continue;
               
            options.put(new selectOption(a.getValue(), a.getLabel()));
        }
        
        return options;
    }
    
    public List<SelectOption> getCountriesOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        countryOptions.add(new SelectOption('','-None-'));
        countryOptions.add(new SelectOption('INDIA','India'));
        countryOptions.add(new SelectOption('USA','USA'));
        countryOptions.add(new SelectOption('United Kingdom','UK'));
        countryOptions.add(new SelectOption('Germany','Germany'));
        countryOptions.add(new SelectOption('Ireland','Ireland'));
        countryOptions.add(new SelectOption('bangladesh','bangladesh'));
        countryOptions.add(new SelectOption('pakistan','pakistan'));
        countryOptions.add(new SelectOption('srilanka','srilanka'));
        countryOptions.add(new SelectOption('bhutan','bhutan'));
 
        return countryOptions;
    }
}
 
ankur khattriankur khattri
I am getting this error now.
Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Class.Picklist.getPicklistOptions: line 21, column 1
sslodhi87sslodhi87
Check this latest one
public class Picklist
{
    public String strPicklist1    {get;set;}
    public String strPicklist2    {get;set;}
    public String strPicklist3    {get;set;}
    public String strPicklist4    {get;set;}
    public String strPicklist5    {get;set;}
    public String strPicklist6    {get;set;}
    public String strPicklist7    {get;set;}
    public String strPicklist8    {get;set;}
    public String strPicklist9    {get;set;}
    public String strPicklist10    {get;set;}
    
    public Picklist()
	{
		strPicklist1 = '';
		strPicklist2 = '';
		strPicklist3 = '';
		strPicklist4 = '';
		strPicklist5 = '';
		strPicklist6 = '';
		strPicklist7 = '';
		strPicklist8 = '';
		strPicklist9 = '';
		strPicklist10 = '';
		
	}
    
    List<SelectOption> countryOptions = new List<SelectOption>{
                                                                new SelectOption('','-None-'),
                                                                new SelectOption('INDIA','India'),
                                                                new SelectOption('USA','USA'),
                                                                new SelectOption('United Kingdom','UK'),
                                                                new SelectOption('Germany','Germany'),
                                                                new SelectOption('Ireland','Ireland'),
                                                                new SelectOption('bangladesh','bangladesh'),
                                                                new SelectOption('pakistan','pakistan'),
                                                                new SelectOption('srilanka','srilanka'),
                                                                new SelectOption('bhutan','bhutan')
                                                                };
    
    public List<SelectOption> getPicklistOptions1()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions2()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions3()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions4()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    public List<SelectOption> getPicklistOptions5()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions6()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions7()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    
    public List<SelectOption> getPicklistOptions8()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    
    public List<SelectOption> getPicklistOptions9()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )
               || (strPicklist10 != null && strPicklist10.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    
    public List<SelectOption> getPicklistOptions10()
    {
        List<SelectOption> options = new List<SelectOption>{new SelectOption('','-None-')};
        
        for(SelectOption a : countryOptions) 
        { 
            if((strPicklist1 != null && strPicklist1.indexOf(a.getValue()) != -1 )
               || (strPicklist2 != null && strPicklist2.indexOf(a.getValue()) != -1 )
               || (strPicklist3 != null && strPicklist3.indexOf(a.getValue()) != -1 )
               || (strPicklist5 != null && strPicklist5.indexOf(a.getValue()) != -1 )
               || (strPicklist6 != null && strPicklist6.indexOf(a.getValue()) != -1 )
               || (strPicklist7 != null && strPicklist7.indexOf(a.getValue()) != -1 )
               || (strPicklist8 != null && strPicklist8.indexOf(a.getValue()) != -1 )
               || (strPicklist9 != null && strPicklist9.indexOf(a.getValue()) != -1 )
               || (strPicklist4 != null && strPicklist4.indexOf(a.getValue()) != -1 )) continue;
               
            options.add(a);
        }
        return options;
    }
    public void getCountriesOptions() 
    {
       //PicklistOptions = getPicklistOptions();
    }
}


<apex:page controller="Picklist" sidebar="false"> 
    <apex:form >
		<apex:sectionHeader title="PickList Value Selection"/>    
		<apex:actionfunction name="updatepicklist" rerender="pb" action="{!getCountriesOptions}"/>
		<apex:PageBlock  id="pb">
			<apex:pageBlockSection collapsible="false" >
				<apex:selectList value="{!strPicklist1}" multiselect="false" size="1" onchange="updatepicklist();" >
					<apex:selectOptions value="{!PicklistOptions1}" />
				</apex:selectList>
			</apex:pageBlockSection>    
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist2}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions2}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist3}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions3}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist4}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions4}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist5}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions5}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist6}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions6}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist7}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions7}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist8}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions8}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist9}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions9}" />
				</apex:selectList>
			</apex:pageBlockSection>
			<apex:pageBlockSection collapsible="false">
				<apex:selectList value="{!strPicklist10}" multiselect="false" size="1" onchange="updatepicklist();">
					<apex:selectOptions value="{!PicklistOptions10}" />
				</apex:selectList>
			</apex:pageBlockSection>   
		</apex:PageBlock>
  </apex:form>
</apex:page>

This is going to help you surely.

Thanks
sslodhi87sslodhi87
Hi Ankur,

Please let me know if this works for you.. also choose as best answer if that help you
mritzimritzi
Hi @ankur

I have made few changes to your code, and its workinh pretty fine.
please have a look

Apex:
public with sharing class Picklist 
{
    public String err{get;set;}
    //shortened variable names
    public String sC1{get;set;}
    public String sC2{get;set;}
    public String sC3{get;set;}
    public String sC4{get;set;}
    public String sC5{get;set;}
    public String sC6{get;set;}
    public String sC7{get;set;}
    public String sC8{get;set;}
    public String sC9{get;set;}
    public String sC10{get;set;}
    
    //changed getCountriesOptions to cOs
    public List<SelectOption> cOs;
    public boolean disable{get; set;}
    
    public Picklist(){
        //populated selecOption List in constructor
        cOs = new List<SelectOption>();
        cOs.add(new SelectOption('','-None-'));
        cOs.add(new SelectOption('INDIA','India'));
        cOs.add(new SelectOption('USA','USA'));
        cOs.add(new SelectOption('United Kingdom','UK'));
        cOs.add(new SelectOption('Germany','Germany'));
        cOs.add(new SelectOption('Ireland','Ireland'));
        cOs.add(new SelectOption('bangladesh','bangladesh'));
        cOs.add(new SelectOption('pakistan','pakistan'));
        cOs.add(new SelectOption('srilanka','srilanka'));
        cOs.add(new SelectOption('bhutan','bhutan'));
    }
     
    public List<SelectOption> getCountriesOptions() {
        //simply return already populated list
        return cOs;
    }
    //added new function, it is executed whenever selectList value is changed
    public void removeCountry() {
        Integer listSize = cOs.size();
        //excluded index 0 in loop as it holds null value
        for(Integer i=1;i<listSize;i++){
            if(cOs[i].getValue()==sC1 || cOs[i].getValue()==sC2 || cOs[i].getValue()==sC3 || cOs[i].getValue()==sC4 || cOs[i].getValue()==sC5 || cOs[i].getValue()==sC6 || cOs[i].getValue()==sC7 || cOs[i].getValue()==sC8 || cOs[i].getValue()==sC9 || cOs[i].getValue()==sC10){
                cos[i].setDisabled(true);
            }
            else if(cOs[i].getValue()!=sC1 && cOs[i].getValue()!=sC2 && cOs[i].getValue()!=sC3 && cOs[i].getValue()!=sC4 && cOs[i].getValue()!=sC5 && cOs[i].getValue()!=sC6 && cOs[i].getValue()!=sC7 && cOs[i].getValue()!=sC8 && cOs[i].getValue()!=sC9 && cOs[i].getValue()!=sC10){
                cos[i].setDisabled(false);
            }
        }
    }
    
}

VF Page
<apex:page controller="Picklist" sidebar="false" showheader="false"> 
    <apex:form >
    <h4>{!err}</h4>
    <apex:sectionHeader title="PickList Value Selection"/>
            <apex:PageBlock >
                <apex:pageBlockSection id="pbs1" collapsible="false" >
                    <apex:selectList value="{!sC1}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <!--added following line in each selectList to call apex method -->
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>    
                <apex:pageBlockSection id="pbs2" collapsible="false">
                    <apex:selectList value="{!sC2}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs3" collapsible="false">
                    <apex:selectList value="{!sC3}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs4" collapsible="false">
                    <apex:selectList value="{!sC4}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs5,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs5" collapsible="false">
                    <apex:selectList value="{!sC5}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs6,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs6" collapsible="false">
                    <apex:selectList value="{!sC6}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs7,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs7" collapsible="false">
                    <apex:selectList value="{!sC7}" multiselect="false" size="1">
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs8,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs8" collapsible="false">
                    <apex:selectList value="{!sC8}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs9,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs9" collapsible="false">
                    <apex:selectList value="{!sC9}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs10"/>
                    </apex:selectList>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="pbs10" collapsible="false">
                    <apex:selectList value="{!sC10}" multiselect="false" size="1" >
                        <apex:selectOptions value="{!countriesOptions}" />
                        <apex:actionSupport action="{!removeCountry}" event="onchange" rerender="pbs1,pbs2,pbs3,pbs4,pbs5,pbs6,pbs7,pbs8,pbs9"/>
                    </apex:selectList>
                </apex:pageBlockSection>   
            </apex:PageBlock>
  </apex:form>
  <!--
  <script href="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script>
      $(document).ready(function(){
          alert('hi');
          $('select').change(function(){
              var selectedCountry = $(this).val();
              alert(selectedCountry);
              $('select').each(function(){
                  if($(this).find('option').val()==selectedCountry){
                      $(this).find('option').attr('disabled','true');
                  }
              });
          }); 
      });
  </script>-->
</apex:page>



Hit like if it helped you  in anyways. Select it as Best answer it it solved your problem. Cheers
This was selected as the best answer
ankur khattriankur khattri
thanks mritzi and sslodhi87.it helped a lot both worked fine.