You need to sign in to do that
Don't have an account?
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;
}
}
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.