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
ani123ani123 

onchange picklist section visibilty

hi i have a vf page  picklist "countries".i have each section for countries on change of my selection in picklist i want the section visibilty for selected country.

 

Kindly give me solution urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

bob_buzzardbob_buzzard

Is this a custom picklist (i.e. an apex:selectlist) or an apex:inputfield?

ani123ani123

apex:selectlist

bob_buzzardbob_buzzard

The onchange event should give you what you need.  Here's an example from one of my dev orgs:

 

<apex:SelectList value="{!chosenAccount}" onchange="addRemoveContacts(this.options[this.selectedIndex])">
   <apex:selectOptions value="{!accountMatches}" />
</apex:SelectList>

In this case, the selectlist is a list of account id/name, plus a NEW option.  When the user changes the selected account, the following javascript is executed:

 

 <script>
    var prevOptionValue='';
    function addRemoveContacts(selOption)
    {
       if (selOption.value=='NEW')
       {
          removeContact();
       }
       else 
       {
          addContact();
       }
    }
 </script>

 addContact and removeContact are actionfunctions .  The addContact action method sets up a list of contacts available on an existing account so that the user can select one of those.

 

public void addContact()
{
  // the user has chosen an entry that is to merge with an existing account
  contactMatches=new List<SelectOption>();
  List<Contact> matches=[select id, Name from Contact 
  	               where (FirstName = :theLead.FirstName 
  	                      OR LastName=:theLead.LastName) 
   	                      AND accountId=:chosenAccount];
   	  	                      
   contactMatches.add(new SelectOption('NEW', 'Create new contact - ' + theLead.Name));
   for (Contact cont : matches)
   {
      contactMatches.add(new SelectOption(cont.id, 'Merge with existing contact - ' + cont.Name));
   }
     	 
   chosenContact='NEW';

}
   

 Obviously this isn't a straightforward cut and paste, but hopefully gets you started.