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
Guru Vemuru 1Guru Vemuru 1 

How to Pop-up massage in visualforce page based on condition?

Hi everyone,

I have Visualforce page and i want populate massage based on cirtain condition while saving the record.
Here is my code:

<apex:page standardController="Travel_Request__c" extensions="DataValidate" showHeader="true" sidebar="false" title="Travel Request"> 

    
  
  <apex:form > 
     
<script>
    function validateName(trdesID,)
    {
        var desig=document.getElementById(trdesID);
        
        
        if(pc.Designation__c == tc.Designation__c && tc.Advance__c=='Cash Advance' && tc.Amount__c > pc.Cash_Advance__c)
        {
                    var msg="HEY";
                        alert(msg);
                    return true;
           }
        
       
    }
  </script>
 <apex:slds />  
 <div class="slds-scope">
 <apex:outputPanel id="TR">
 <apex:pageBlock title="Travel Request">
 <apex:pageBlockSection columns="2" title="General Information" collapsible="false">
 
       <apex:inputField value="{!Travel_Request__c.Name}"/>   
          
       <apex:inputField value="{!Travel_Request__c.Branch__c}"/>   
       <apex:inputField value="{!Travel_Request__c.Department__c}" /> 
       <apex:inputField value="{!Travel_Request__c.Designation__c}" id="trdesigID"/> 
       <apex:inputField value="{!Travel_Request__c.Travel_Mode__c}"/>   
       <apex:inputField value="{!Travel_Request__c.Travel_Start_Date__c}"/>
       <apex:inputField value="{!Travel_Request__c.Travel_End_Date__c}"/>
        <apex:inputField value="{!Travel_Request__c.Meals_Choice__c}"/>
        <apex:inputField value="{!Travel_Request__c.Status__c}" />
       <apex:inputField value="{!Travel_Request__c.Travel_Type__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>

       <apex:inputField value="{!Travel_Request__c.Accommodation_Required__c}">
       <apex:actionSupport event="onchange" rerender="TR" />
      
                    </apex:inputField>
         <apex:inputField value="{!Travel_Request__c.Advance__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
         <!---
         <apex:inputField value="{!Travel_Request__c.Travel_Card_Loaded__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
         <apex:inputField value="{!Travel_Request__c.Travelers_Cheque__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
              --->      
                </apex:pageBlockSection>                
                <apex:pageBlockSection columns="2" Title="Travel Type Information">                     
         <apex:inputField value="{!Travel_Request__c.Proposed_Countries_To_Visit__c}" rendered="{!IF( Travel_Request__c.Travel_Type__c == 'Overseas',true,false  )}" />                   
          <apex:inputField value="{!Travel_Request__c.Proposed_City__c}" rendered="{!IF( Travel_Request__c.Travel_Type__c == 'Overseas',true,false  )}" />
                   
                </apex:pageBlockSection> 
        
        
      
   <apex:pageBlockSection columns="2" collapsible="true" title="Accomodation Information" > 
   <apex:inputField value="{!Travel_Request__c.Check_In_Date__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
   <apex:inputField value="{!Travel_Request__c.Check_Out_Date__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
   <apex:inputField value="{!Travel_Request__c.City_Name__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
                          
         
</apex:pageBlockSection>
<apex:pageBlockSection columns="2" collapsible="true" title="Advance Section" > 
   <apex:inputField value="{!Travel_Request__c.Amount__c}" 
                          rendered="{!IF( Travel_Request__c.Advance__c == 'Cash Advance',true,false )}" />
   <apex:inputField value="{!Travel_Request__c.Travel_card_Amount__c}" 
                      rendered="{!IF( Travel_Request__c.Advance__c == 'Travel Card Loaded',true,false )}" />
   <apex:inputField value="{!Travel_Request__c.Card_Number__c}" 
                          rendered="{!IF( Travel_Request__c.Advance__c == 'Travel Card Loaded',true,false )}" />       
                          
  <apex:inputField value="{!Travel_Request__c.Travelers_Cheque_Number__c}" 
                     rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                           
   <apex:inputField value="{!Travel_Request__c.Quantity__c}" 
                       rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                          
  <apex:inputField value="{!Travel_Request__c.Denomination__c}" 
                     rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                          
</apex:pageBlockSection>
</apex:pageBlock>
            <div align="center" draggable="false" >
            <apex:commandButton action="{!Save}" value="Save" oncomplete="validateName('{!$Component.trdesigID}')"/>
            <apex:commandButton action="{!Cancel}" value="Cancel"/>
            <apex:commandButton action="{!Edit}" value="Edit"/>
            </div>
</apex:outputPanel>
</div>
</apex:form>
</apex:page>
RD@SFRD@SF
Hi Guru,

1. You can use the alert function in a Java script.
2. Have a panel or div which is rendered on a condition

I am sure there are ways, these can be the starting points

RD
shubhi vijayvergiashubhi vijayvergia
Hi Guru,
I have below vf page and controller that generate alert on button click you can use it as per your condition.
<apex:page Controlle="TestAlert">

<apex:form >
<apex:pageBlock >
<apex:commandButton value="Show alert" action="{!alert}" rerender="alert" status="status"/>
 
             <apex:outputPanel id="alert">

                <apex:outputPanel id="popInnerOutputPnl" styleClass="customAlert" layout="block" rendered="{!displayAlert}">
                     <apex:commandButton value="X" title="Close the alert" action="{!closeAlert}" styleClass="closeButton" rerender="alert">
                     </apex:commandButton>
                     <apex:pageblockSection >                         
                         
                         <apex:pageblockSectionItem >
                          <apex:outputLabel>This is alert!!!</apex:outputLabel>                      
                         </apex:pageblockSectionItem>
                     </apex:pageblockSection>
                     <apex:commandButton value="Ok" action="{!redirectAlert}" styleClass="closeButton" rerender="alert">
                     </apex:commandButton>
                </apex:outputPanel>
            </apex:outputPanel>
            
            </apex:pageBlock>
            
              </apex:form>
              
                  <style type="text/css">
.customAlert {
    background-color: white;
    border-style: solid;
    border-width: 2px;
    left: 20%;
    padding: 10px;
    position: absolute;
    z-index: 9999;
    width: 500px;
    top: 20%;
}

.disabledTextBox {
    background-color: white;
    border: 1px solid;
    color: black;
    cursor: default;
    width: 90px;
    display: table;
    padding: 2px 1px;
    text-align:right;
}   

.closeButton {
    float: right;
}
</style>


</apex:page>

below is controller
public with sharing class TestAlert {

    public Boolean displayAlert {get;set;}
 
    public void alert()
    {
        
    displayAlert = true;

    
    }
    
    public void closeAlert() {
        displayAlert = false;
        
    }
    
    public PageReference redirectAlert()
    {
		displayAlert = false;

		 return null;    
    }
    


}