How to show apex:pageMessages in javascript? Here is my code in vf page

<apex:form id="frm">
                            <apex:pageBlock id="pb1">
                            <div style="position: absolute; left: 100px; top: 50px;">
                            <apex:pageMessages id="showmsg"></apex:pageMessages>
  • 2
    What do you mean by show them in javascript?
    – dphil
    Commented Oct 1, 2014 at 19:54
  • Give the alert or store in another variable in javascript on oncomplete of action function Commented Oct 1, 2014 at 19:55
  • Do you have an associated controller as well? You could place them in a variable then and pass that variable to the javascript.
    – dphil
    Commented Oct 1, 2014 at 20:03
  • How I do that ? Please tell me Commented Oct 2, 2014 at 7:13

1 Answer 1


This is the simplest way to achieve it

You can assign the the error Message to alertMsg to serve your purpose.


<apex:page controller="Js_Alert" >

Controller :

public class Js_Alert {

public string alertMsg{get;set;}

public SE_Js_Alert()

    alertMsg = 'alert(\'Error Msg\'); ';


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .