You need to sign in to do that
Don't have an account?

how to save the selected value from select list to a variable each time
i have the selectlist
I need to overwrite the variable every time I selecе.because my choice is based on this value
apex
vsforce
<!-- Select a doctor --> <apex:pageBlockSection > Select a doctor: <apex:selectList size="1" multiselect="false" value="{!selectedDoctor}"> <apex:selectOptions value="{!doctorSelectOptionList}"/>
I need to overwrite the variable every time I selecе.because my choice is based on this value
apex
public with sharing class app_test_1 { public Appointment__c appt {get; set;} public string Doc_name {get;set;} public string Patient_name {get;set;} public List<Doctor__c> doclists{set;get;} public String selectedDoctor {get; set;} public String selectedPatient {get; set;} public Datetime appDate {get; set;} public List<Doctor__c> DoctorList {get;set;} public List<SelectOption> doctorSelectOptionList {get;set;} public List<Patient__c> PatientList {get;set;} public List<SelectOption> patientSelectOptionList {get;set;} public List<Appointment__c> appList {get;set;} public string str_1 {get;set;} Public Integer size{get;set;} Public Integer noOfRecords{get; set;} public List<SelectOption> paginationSizeOptions{get;set;} public app_test_1(){ str_1='gmak'; Patient_name = 'a015g00000KIFvGAAX'; appt=new Appointment__c(); // getApp(); doctorSelectOptionList = new List<SelectOption>(); patientSelectOptionList = new List<SelectOption>(); DoctorList = [SELECT iD, Name,working_hours_start__c FROM Doctor__c]; //TimeStart = DoctorList.working_hours_start__c; for (Doctor__c doc : DoctorList){ doctorSelectOptionList.add(new SelectOption(doc.Id, doc.Name)); } PatientList = [SELECT Id, Name FROM Patient__c]; for (Patient__c patient : PatientList){ patientSelectOptionList.add(new SelectOption(patient.Id, patient.Name)); } size=10; paginationSizeOptions = new List<SelectOption>(); paginationSizeOptions.add(new SelectOption('5','5')); paginationSizeOptions.add(new SelectOption('10','10')); paginationSizeOptions.add(new SelectOption('20','20')); paginationSizeOptions.add(new SelectOption('50','50')); paginationSizeOptions.add(new SelectOption('100','100')); } public PageReference save() { return null; } public PageReference saveandnew() { Doc_name = selectedDoctor; appt.Doctor__c=selectedDoctor; appt.patient__c=Patient_name; insert appt; PageReference PageRef = new PageReference('/apex/vs_g_t_01'); appt.clear(); return PageRef; } public list<Doctor__c> getDoc() { return [Select Name, working_hours_start__c,Working_Hours_End__c From Doctor__c where Name Like :str_1]; } public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [select ID,NAme,Doctor__r.Name,patient__r.Name,Duration_in_minutes__c ,Appointment_Data__c FROM Appointment__c ])); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; } set; } //Changes the size of pagination public PageReference refreshPageSize() { setCon.setPageSize(size); return null; } // Initialize setCon and return a list of record public List<Appointment__c> getApp() { return (List<Appointment__c>) setCon.getRecords(); } }
vsforce
<apex:page controller="app_test_1"> <apex:form > <apex:pageBlock title="appointment"> <!-- Select a doctor --> <apex:pageBlockSection > Select a doctor: <apex:selectList size="1" multiselect="false" value="{!selectedDoctor}"> <apex:selectOptions value="{!doctorSelectOptionList}"/> </apex:selectList> </apex:pageBlockSection> <apex:pageBlock > <apex:pageBlockTable value="{!doc}" var="item"> <apex:column value="{!item.working_hours_start__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!doc}" var="item"> <apex:column value="{!item.Working_Hours_End__c}"/> </apex:pageBlockTable> </apex:pageBlock> <!-- Select a patient --> <apex:pageBlockSection > Select a patient: <apex:selectList size="1" value="{!selectedPatient}"> <apex:selectOptions value="{!patientSelectOptionList}"/> </apex:selectList> </apex:pageBlockSection> <apex:pageBlockSection > <apex:inputField label="Duration in minutes" value="{!appt.Duration_in_minutes__c}" required="false"/> </apex:pageBlockSection> <!-- Appointment date --> <apex:pageBlockSection > <apex:inputField label="Appointment date" value="{!appt.Appointment_Data__c}" required="false"/> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton reRender="pbId" value="Add new appointment" action="{!saveandnew}" /> </apex:pageBlockButtons> </apex:pageBlock> <script type="text/javascript"> console.log('{!selectedDoctor}'); </script> <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/> <apex:pageBlock id="pbId"> <apex:pageBlockSection title="All Opportunities" collapsible="false" columns="1"> <apex:pageBlockTable value="{!App}" var="oppObj"> <apex:column headerValue="Action"> <apex:outputLink value="{!URLFOR('/' + oppObj.Id)}"> View </apex:outputLink> </apex:column> <apex:column headerValue="Doctor Name"> <apex:outputField value="{!oppObj.Doctor__r.Name}"/> </apex:column> <apex:column headerValue="Patient Name"> <apex:outputField value="{!oppObj.patient__r.Name}"/> </apex:column> <apex:column headerValue="Appointment Data"> <apex:outputField value="{!oppObj.Appointment_Data__c}"/> </apex:column> <apex:column headerValue="Appointment Duration"> <apex:outputField value="{!oppObj.Duration_in_minutes__c}"/> </apex:column> </apex:pageBlockTable> <apex:panelGrid columns="8"> <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();"> <apex:selectOptions value="{!paginationSizeOptions}"/> </apex:selectList> <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords, (setCon.pageNumber * size))} of {!noOfRecords} </apex:outputText> <apex:outputPanel > <apex:actionStatus id="fetchStatus" > <apex:facet name="start" > <img src="/img/loading.gif" /> </apex:facet> </apex:actionStatus> </apex:outputPanel> </apex:panelGrid> </apex:pageBlockSection> </apex:pageBlock> <a class="btn" onclick="checkDoubleSubmit(this)" target="_top">Update Opportunity</a> <script> function lod(isReLoad) { if(isReLoad == true) { } } </script> <script> var isClicked = false; function checkDoubleSubmit(obj){ if (isClicked) { alert('{!size}');//For testing message only. return false; } else { isClicked = true; alert('{!size}'); updateOpportunity(); return false; } } </script> </apex:form> </apex:page>