You need to sign in to do that
Don't have an account?
Priyadarshini Manoharan 3
How to fetch a picklist value selected in a VF page before the record is saved?
There is a picklist field on a VF page, after clicking on new button once I select a picklist value in the field, how do I fetch the value, before it is saved in the database. I need to use this fetched value to populate another field before the record is saved.
on button click, are you calling any method in the controller? if yes, you can write the logic there itself.
let me know if i didnt understand the requirement properly.
Thanks
Thanks
Thanks
My requirement is different, I have a field Issue Type with values Access, Data, Performance, while creating a new case if I select Access, I need to populate the description field with please provide login details etc. even before the record is saved by clicking submit case button, similarly for different values of Issue Type there are different values of description
check this blog. it may help you
http://www.cloudforce4u.com/2013/07/using-javascript-in-visualforce-page.html
Let me try and get back, in case of any queries
Hi Rohit,
I was able to get half way through. I was able to get the picklist value even before the record was saved through java script. I now need to set a value to Description field based on the value of the Product__c field fetched through java script. How can I achieve that? Below is the code
If Product is A, I want to set description as Please enter details for A
If Product is B, I want to set description as Enter Username, password etc. When issue occured etc...
If Product is C, I want to set description as Is performance slow? etc
Apex page
<apex:page standardController="Case" extensions="CaseStdControllerExt" title="Contact Us" showHeader="true" standardStylesheets="true" docType="html-5.0">
<apex:form id="frm">
<apex:pageBlock title="Enter Case Details" rendered="true">
<apex:pageBlockButtons >
<apex:commandButton value="Submit Case" action="{!savecase}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Case Information" collapsible="false" columns="1">
<apex:inputField value="{!Case.Product__c}" id="inptID" onchange="MyjavaFunction('{!$Component.inptID}')" />
<apex:inputField value="{!Case.Description}" id="casedesc"/>
</apex:PageBlockSection>
</apex:pageBlock>
</apex:form>
<!-- Java script starts Here -->
<script>
function MyjavaFunction(ReceiveInputID){
var inputValue = document.getElementById(ReceiveInputID).value;
if(inputValue == ''){
alert('You did not eneter any value in input box');
}
else
{
alert(' You entered :: '+inputValue);
}
}
</script>
</apex:page>
Standard Extension controller
public class CaseStdControllerExt {
private final Case webcase;
public CaseStdControllerExt(ApexPages.StandardController controller) {
webcase = (Case)controller.getRecord();
}
public PageReference savecase()
{
upsert(webcase);
PageReference p = new ApexPages.StandardController(webcase).view();
p.setRedirect(true);
return p;
}
}