function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sanu VermaSanu Verma 

how to remove Picklist value on vf page

I have an input text field on vf page where i called custom picklist value. But want to restrict some value on condition. means want to hide some value on condition. but not able to do so.
here is my code:-
<div class="slds-form-element slds-m-around_x-small">
                                            <label class="slds-form-element__label " style="font-size: 14px;font-weight: 600;">Payment Method:&nbsp;</label>
                                            <div class="slds-form-element__control">
                                                <apex:inputField styleClass="slds-select optionPaymentMethod" value="{!tempOpportunity.Payment_Method__c}" id = "pmethod" >
                                                    <apex:actionSupport event="onchange" action="{!dummyCall}" rerender="pnlManualPaymentMethod" />
                                                </apex:inputField>
                                                <!--<apex:selectList value="{!tempOpportunity.Payment_Method__c}" size="1" >-->
                                                <!--    <apex:selectOptions value="{!methodSelectOptionList}"/>-->
                                                <!--</apex:selectList>-->
                                            </div>
                                        </div>

and the other one
 
function showPaymentMethod() {
                          var methodType = document.querySelectorAll('[id$ = "pmethod"]') [0];
                          if(tempOpportunity.AccountId == null){
                                for(var i = 0; i < methodType.length; i++) {
                                    if(methodType.options[i].value == 'Wallet'){
                                     methodType.hide(i);
                                  }
                          }
                                    
                         }
                         return false;
Deepali KulshresthaDeepali Kulshrestha
Hi Sanu,

Since your picklist field is on a Visualforce page, you can use some jQuery magic...

Give your field a unique id.

<apex:inputField value="{!My_Picklist__c}" <strong><font color="#FF0000">id="myPicklist"</font></strong> />
 
Then, remove the option with the blank value as follows:

<script type="text/javascript" src="<a href="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js" target="_blank" rel="nofollow">https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js</a>"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('[id*=<strong><font color="#FF0000">myPicklist</font></strong>] option[value=""]').remove();
    }); 
</script>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha