JavaScript: Displaying Message after a Action, say Form Submit

You need to display a message after any action to confirm about successful completion of the action or for some error.

Suppose user has submitted a web form and you got everything fine. So in PHP you have this script:

<?php
if (count($_POST))
{
// checking / validation etc
// Db insert etc
## Now display message to users about successful form submit
echo '<script> alert("Form submitted successfully/ Email sent etc.") </script>';
}
?>
<html>
<head></head>
<body>
<?php
## 2. message
?>
<?php
if (! count($_POST))
{
    ?>
<form method="post" action="">
...
</form>
    <?php
}
?>
</body>
</html>

In the above method, Visitor will get javascript alert box having your message.
Many does not like javascript alert box jumped to them. User need to click on them.

Instead of using above method, have a message displayed using PHP itself on web page.
Replace <code>echo '<script> alert("Form submitted successfully/ Email sent etc.") </script>';</code>
with <code> $msg = 'Form submitted successfully/ Email sent etc';</code>
and write this line
<code>
echo @$msg;
</code>
below the line ## 2. message.
You can add some color/ design to your message here:
$msg = '<p><b style="color:blue">Form submitted successfully/ Email sent etc</b></p>';

Comments are open for an year period. Please, write here on Facebook page.