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

Show popup message on VF page

Hi All,


I have created a Visualforce page with input fields.When user clicks on save button a logic executes in the controller and need to show up a pop message to user saying fill the values in the fields.


Can you please let me know how this could be acheived.





Srilakshmi B


You can make use of javascript 'alert' methods. If it is making some fields mandatory then I don't see requirement of pop-up message, instead use validation rules.


Try this

<apex:page controller="popup">
    <apex:form >
        <apex:commandButton value="Show Pop up" action="{!showPopup}" rerender="popup"/>
        <apex:pageBlock >
            Lorem ipsum ..... dummy stuff to show the popup is above content
        <apex:outputPanel id="popup">
            <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
                Lorem ipsum <br/><br/><br/>
                <apex:commandButton value="Hide Pop up" action="{!closePopup}" rerender="popup"/>
    <style type="text/css">
            background-color: white;
            border-style: solid;
            border-width: 2px;
            left: 50%;
            position: absolute;
            z-index: 9999;
            /* These are the 3 css properties you will need to tweak so the pop 
            up displays in the center of the screen. First set the width. Then set 
            margin-left to negative half of what the width is. You can also add 
            the height property for a fixed size pop up.*/
            width: 500px;
            margin-left: -250px;


public class popup {
    public boolean displayPopup {get; set;}
    public void closePopup() {
        displayPopup = false;
    public void showPopup() {
        displayPopup = true;



Thanks for the solution.But actualy my requirement is something like this.

I have Reject button on my VF page page when user clicks on the reject button without entering in the Rejection reason field I should show Alert message to him.I think I need to use the javascript here.


Could please provide me with code snippet to acheive this.



Srilakshmi B


To achieve this,


We can use window.showModalDialog('popuppageurl') method.



function fun()







  <apex:commandButton value="Popup" action="{!dosomeaction}" onclick="fun()" />




Like this you have to use.


Write a javaScript function displaying on what field you want with a condition




and diaplay message with alert("******  The Message  **************");

Hi @symantecAP
Thanks for this suggession. I have implemented the same and it worked.

Nasir Jawed