Activity Forums Salesforce® Discussions How to make picklist as required (thru javascript) in Salesforce ?

  • shariq

    September 22, 2018 at 11:23 am

    We need to make a custom catch and in that custom catch, we need to compose JavaScript code to check whether the picklist esteem is invalid.

  • Parul

    September 22, 2018 at 12:00 pm

    use this code snippet:

    I have used Javascript and its working.

    <apex:page standardController="Lead" >
    function validateForm()
    var x = document.getElementById('{!$Component.exname}');
    if (x == null || x == "")
    alert("Please select Value");
    return false;

    (Add onsubmit="return validateForm()"  in to Web-To-Lead form code as shown in below)
    <form id="enquiryFrm" action="" onsubmit="return validateForm()" method="post" >

    <section class="form-row">
    <apex:outputLabel value="Interested In:"/>
    <apex:outputPanel layout="block" styleClass="requiredInput">
    <apex:outputpanel layout="block" styleClass="requiredBlock"/>
    <section class="select-outer">
    <select class="select" id="00N3600000NxhqK" name="exname" title="Interested In">
    <option value="">Please select</option>
    <option value="Mobile Apps">Mobile Apps</option>
    <option value="Web Apps">Web Apps</option>
    <option value="Salesforce">Salesforce</option>
    <option value="Technical Support">Technical Support</option>
    <option value="Application Support">Application Support</option>


    Hope this helps:



Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos