[SalesForce] Rerender pageblock on change of picklist

I am working with with picklist. Here I have to show a pageblocksection on change picklist but when I change the picklist it rerenders all the page and I am able to see pageblocksection but my picklist option get vanish from the page. Below is my code please check!

 <span id="idSpan" style = "display:none"> 
           <apex:pageBlockSection title="Search For Public Group" columns="1" id="Details"> 
               <apex:selectList size="1" value="{!selectedgrpId}">  
                   <apex:selectOptions value="{!GroupNames}"/>
                   <apex:actionSupport event="onchange" />
               </apex:selectList>
           </apex:pageBlockSection> 
       </span>

I have to show below pageblocksection.

<apex:pageBlockSection title="Enter User Id" columns="1" id="sec1" rendered="{!selectedgrpId != null}"> 
           <apex:inputTextArea value="{!UserId}"/> 
           <apex:commandButton value="Submit" action="{!useraddition}"/>   
       </apex:pageBlockSection>

Best Answer

You have two problems here:

  1. Check Anurag answer. Your action support need to reRender something.
  2. It's a common mistake with reRender. You can't reRender an element that was never rendered on the page (because the page won't find the Id). Instead, you have to reRender a parent element wich will trigger the evaluation of the rendered attributte of it's children. Try something like this:
<span id="idSpan" style = "display:none"> 
    <apex:pageBlockSection title="Search For Public Group" columns="1" id="Details"> 
        <apex:selectList size="1" value="{!selectedgrpId}">  
            <apex:selectOptions value="{!GroupNames}"/>
            <apex:actionSupport event="onchange" reRender="wrapper" />
        </apex:selectList>
    </apex:pageBlockSection> 
</span>

<apex:outputPanel layout="none" id="wrapper">
    <apex:pageBlockSection title="Enter User Id" columns="1" id="sec1" rendered="{!selectedgrpId != null}"> 
        <apex:inputTextArea value="{!UserId}"/> 
        <apex:commandButton value="Submit" action="{!useraddition}"/>   
    </apex:pageBlockSection>
</apex:outputPanel>