Objective : To display the chosen the picklist value as javascript alert when the button is clicked
This is my VF Page
What actually happens
1. After page load when I click on "Go" it just shows an empty popup like this.
2. After choosing a type from the picklist when I click on the button the page simply refreshes.
This is my controller code
public with sharing class GatewayController {
public String chosen_type{get;set;}
public String test_value{get;set;}
public GatewayController(ApexPages.StandardController controller) {
}
public List<SelectOption> getTypes()
{
Schema.DescribeFieldResult fieldResult = Aus_Expense__c.Type__c.getDescribe();
List<Schema.PickListEntry> ple = fieldResult.getPickListValues();
List<SelectOption> options = new List<SelectOption>();
test_value = 'This is a test';
for(Schema.PickListEntry s : ple)
{
options.add(new SelectOption(s.getLabel(),s.getValue()));
}
return options;
}
}
VF Page Tag
<apex:page standardController="Aus_Expense__c" extensions="GatewayController" >
<apex:form >
<apex:pageblock >
<apex:pageBlockButtons >
<apex:commandButton value="GO" onclick="alert({!chosen_type});"/>
</apex:pageBlockButtons>
<apex:outputLabel >Choose a type : </apex:outputLabel>
<apex:selectList size="1" id="types_id" value="{!chosen_type}">
<apex:selectOptions value="{!types}" />
</apex:selectList>
</apex:pageblock>
<apex:pageblock >
<p/>
<apex:outputText >Start Date :</apex:outputText>
<p/>
<apex:outputtext >End Date : </apex:outputText>
<p/>
<apex:outputtext >Type : </apex:outputtext>
<p/>
<apex:outputtext > Begin Amount : </apex:outputtext>
<p/>
<apex:outputtext > End Amount : </apex:outputtext>
</apex:pageblock>
</apex:form>
</apex:page>
Question :
My understanding is that the chosen value from the apex:selectlist will be stored in the controller property {!chosen_type}
.
Is this not right ?.
Can someone explain why my javascript alert (on button click) does not show the chosen picklist value ?