0

I have a picklist called type__c on the visual force edit page.

I need the value of what user has chosen on my url.

Following is the code I am using to get the value.

if({!opp.Type__c == "one"}){
                       baseURL = baseURL + "&Type=Temp";
                   }
else if({!opp.Type__c == "Two"}){
                       baseURL = baseURL + "&Type=Perm";
                   } 

Above code does store the value after I click on save. I mean if that opportunity already have the Type__c selected as ONE by default I get type = temp. but when I change type to TWO it does not return Type = Perm .I than have to save and click on edit again in order for that to pass Type = Perm .

I have tried refreshing form Onchage of picklist value but that doesn't help either.

Any suggestions?

1

You're merging in the value, so an onchange won't exactly help you, unless you also rerender the script, like this:

<apex:outputText id="myScript">
    <script>
    ...
    if({!opp.Type__c=='one'}) {
    ...
    </script>
</apex:outputText>

You can then assign an apex:actionSupport to your picklist:

<apex:inputField value="{!opp.Type__c}">
    <apex:actionSupport event="onselect" reRender="myScript" />
</apex:inputField>

This will cause the script to be updated with the new values when the picklist changes.

Personally, I'd rather do this in JavaScript to avoid the hassle of a round-trip to the server, which may cost many hundreds of millseconds instead of the one millisecond (or so) it takes to query it locally:

var oppTypeField = document.getElementById('{!$Component.form.block.oppType}');
var oppType = oppTypeField.options[oppTypeField.selectedIndex].value;
if(oppType == 'one') {
   ...
  • I appreciate your help @sfdcfox that helped me solving my problem . – Ricky Oct 22 '15 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.