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
akschampakschamp 

problem in getting changed value of picklist

I have one picklist with me, and i am trying to get the selected value of the picklist. below is the code

 

 

VF page :

 

                               <apex:outputlabel value="Select City" for="values" />

                                <apex:actionSupport event="onchange" action="{!getcitylist}" rerender="txt_city"/>                                   
                                 <apex:selectList value="{!cities}" size="1">
                                      <apex:selectOptions value="{!showcities}"/>
                                 </apex:selectList>

                                  <apex:inputText id="txt_city"/>

 

Apex Code :

 

      String sel_city;

      public String cities
        {
            get {return sel_city;}
            set {sel_city=value;}
        }

 

       public List<selectOption> getshowcities()
    {

            List<selectOption> Selectcity = new List<selectOption>();

              List<Regstr__c> citylist = new List<Regstr__c>();
              courselist = [Select  id, city_name__c FROM Regstr__c ];


              SelectCourse.add(new SelectOption('0','Select city'));


              for (Integer j=0;j<citylist .size();j++)
              {

                 
                  Selectcity .add(new SelectOption(citylist [j].id,citylist [j].city_name__c));
                 
              }      
            return Selectcity ;

    }  

   public void getcitylist()  //this function is called onchange event of dropdown

   {

         //once the selected item in the city drop down is changes, here i have to save the selected value of "city"dropdown  list in textbox "txt_city"

      

   }

 

 

 

I am new to salesforce, please suggest me how to write the scipt to save the value of dropdown in textbox.

 

 

Thanks in advance!!!!!!!!!!!!!!!!!!!!!!

Best Answer chosen by Admin (Salesforce Developers) 
akschampakschamp
Thanks a lot!!!!!!!!!!!!!!  :smileyhappy:

All Answers

TehNrdTehNrd
You can replace all of this:

String sel_city; public String cities { get {return sel_city;} set {sel_city=value;} }

 

With this:

public String cities {get; set;}

 


 


TehNrdTehNrd
And change this:

<apex:inputText id="txt_city"/>

to this:

 

<apex:inputText id="txt_city" value="{!cities}/>

 

 

 

akschampakschamp
Thanks a lot!!!!!!!!!!!!!!  :smileyhappy:
This was selected as the best answer