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
balu palavalasabalu palavalasa 

hi i am beginner to salesforce

hi i am a beginner in salesforce.i have a requirement . there are 2 sections in a vf page .in first section there is only one input textbox which takes values for a country field . and a button called "add" once this button is clicked in the backend it has to add the value in country textbox to a selectlist. so how many times we click on add button those many values must be added to select list.there is another button submit. once submit button is clicked the country list must be displayed in 2nd pageblock section . how can i achieve this

vf page code is :
<apex:page Controller="selectlistoption">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
        
            <apex:outputlabel value="Enter Country"/>
            <apex:inputText value="{!str}"/>
            <apex:commandButton value="Add" action="{!setCountry}"/> 
            <apex:commandButton value="submit" rerender="showdetails"/>
        </apex:pageBlockSection>    
        
    <apex:pageBlockSection id="showdetails">
        
            <apex:selectlist size="1" value="{!str}">
           
                <apex:selectoptions value="{!country}"/>
                 </apex:selectlist>
        
 
        
        </apex:pageBlockSection>
                    </apex:pageBlock>
    </apex:form>
 
</apex:page>

------------------------------------------------------------------------apex code -------------------------------------------------------------
public class selectlistoption {
    
    
      public   string str{get;set;}
    

   public  list<selectoption> country{get;set;}
    
    public void setCountry()
    {
         
        country.add(new selectoption(str,str));
       
    }
    
   

}
 
shailesh_rawteshailesh_rawte
hi,

you have to create one method. in that you have to add that var into  country list.
thn you need to rerender that pageblock section.