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
TarentTarent 

List

hi i want that when we select any value any value from list then it should be display using alert.

<apex:page id="p1" controller="Test">

<apex:form id="f1">
<apex:pageBlock id="pb1">
<apex:pageblockSection id="pbs1" >
<apex:selectList id="pl1" value="{!countries}" multiselect="false" >
<apex:selectOptions value="{!items}"/>
</apex:selectList>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>

</apex:page>


public class Test {

String[] countries = new String[]{};
public String[] getCountries() {
System.debug('_________________countries___________'+countries);
return countries;

}

public void setCountries(String[] countries) {
this.countries = countries;
System.debug('_________________countries__set_________'+countries);
}


public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
options.add(new SelectOption('CHINA','China'));
options.add(new SelectOption('LONDON','London'));
return options;
}
}

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

<apex:page id="p1" controller="Test">

 

 <apex:form id="f1">

<apex:pageBlock id="pb1">

<apex:pageblockSection id="pbs1" >

<apex:selectList id="pl1"  value="{!countries}" multiselect="false" onchange="check()">

            <apex:selectOptions value="{!items}"/>

            </apex:selectList>

</apex:pageblockSection>

</apex:pageBlock>

 </apex:form>

 

 <script>

 function check()

 {

var x;

 

  x = (document.getElementById('p1:f1:pb1:pbs1:pl1').value);

 

  alert(x);

   

 }

 </script>

</apex:page>

 

 

public class Test {

 

 String[] countries = new String[]{};

    public String[] getCountries() {

    System.debug('_________________countries___________'+countries);

            return countries;

           

        }

           

        public void setCountries(String[] countries) {

            this.countries = countries;

            System.debug('_________________countries__set_________'+countries);

        }

 

 public List<SelectOption> getItems() {

            List<SelectOption> options = new List<SelectOption>();

            options.add(new SelectOption('US','US'));

            options.add(new SelectOption('CANADA','Canada'));

            options.add(new SelectOption('MEXICO','Mexico'));

             options.add(new SelectOption('CHINA','China'));

            options.add(new SelectOption('LONDON','London'));

            return options;

        }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.