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
Ap30Ap30 

Javascript validation is not working in visualforce page. Need help

Hi All,
In my below code, only name validation is working fine. When amount is blank,send button is not disabled.I could able to send email.
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.

======================================

<apex:page controller="Bookings" id="page">
<script>
    function nameValidation(){
    
      var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
        
        if(n.value == "")
        {
            alert("Name is mandatory");
            return false;
        }
        else{
        return true;
        }
        }
    function amtValidation(){
      
        var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
        if(at.value == "")
        {
           document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
        }
        else
        {
            send();
        }
     }
     function clickMe()
     {
        var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
        var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
        if(a.value == "" )
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else if(b.value == "")
        {
            document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
            return false;
        }
        else
        {
            return true;
        }
    }
     
</script>
 <apex:form id="form">
  <apex:actionFunction action="{!send}" name="send" reRender="pb" />
  <apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
  <apex:pageBlock title="Vendor Registration Form" id="pb">
  <apex:pageBlockSection columns="2" id="pbs">
  Name :<apex:inputText value="{!vcperson}" id="name"/>
  Amount :<apex:inputText value="{!apevent}" id="amt"/>
  City :<apex:inputText value="{!city}" id="city"/>
  Country :<apex:inputText value="{!country}" id="coun"/>
   
  </apex:pageBlockSection>
  <apex:outputPanel id="op">
  <apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
  <apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
  </apex:outputPanel>
  
  
  </apex:pageBlock>
  
  </apex:form>
</apex:page>
ShivankurShivankur (Salesforce Developers) 
Hi Anupriya,

Please check out below thread and discussion, similar example as yours with proper code:
https://developer.salesforce.com/forums/?id=906F000000095BvIAI

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.