How to display error message in popup jquery
<p>How to display error message in popup and if success message comes hide all the form fields and show success message.</p>

<p>Presently i am doing like this:
Placing a success message above the form and closing it after the form close.
error message div placing above the form i.e inside the success div. Please suggest me the best way. Give some sample code so that i can implement this.</p>

<p>my html code:</p>

<pre><code>&lt;div id="successMessage"&gt;
&lt;form method="POST" id="update_form"  onsubmit = "return false;"&gt;
    &lt;div id="errorMessage"&gt;&lt;/div&gt;
    &lt;table align="center"&gt;
        &lt;tr&gt;
            &lt;td align="right"&gt;First Name:&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input type="text" name="firstName" value="&lt;?php echo $firstName; ?&gt;" /&gt; 
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td align="right"&gt;Last Name:&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input type="text" name="lastName" value="&lt;?php echo $lastName; ?&gt;" /&gt; 
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td align="right" colspan="2"&gt;
                    &lt;input type="hidden" name="userId" value="&lt;?php echo $userId; ?&gt;" /&gt;
                    &lt;input type="button" name="updateUserDetails" value="Update" onclick="updateUserDetails();"&gt;
            &lt;/td&gt;
        &lt;/tr&gt;   
    &lt;/table&gt;
&lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>jquery Code:</p>

<pre><code>function editUserDetails(userId, operation){
    currentOperation = operation; 
    $('#editUserDetails').dialog('open');
    $('#editUserDetails').html("Loading...");
    $.ajax({
           type: "POST",
           url: "editUserDetails.php?userId="+userId,                  
           data: "",
           success: function(msg){
               $('#editUserDetails').html(msg);
           },
           error:function(msg){
                 //alert(msg);
                $('#editUserDetails').dialog("close"); 
           }
    });
}

function updateUserDetails(){
        $.ajax({
               type: "POST",
               url: "updateUserDetails.php",                   
               data: $("#update_form").serialize(),
               success: function(msg){
                   if(msg=="Updated Successfully")
                   {
                       $('#successMessage').html(msg);
                   }
                   else
                   {
                       $('#errorMessage').html(msg);
                   }
               },
               error:function(msg){
                    $('#editUserDetails').dialog("close"); 
               }               
         });
    });
});
</code></pre>
