First part  :

<script type=“text/javascript”>
//<![CDATA[
function checkform()
{
document.getElementById('urltosend').action="addmess2.php";
document.forms['addform'].target=”process”;
top.document.forms['addform'].submit();
}
//]]>

</script>

<form id=“urltosend” name=“addform” method=“post” action=“addmess.php”>

<input type=“button” onclick=“checkform()” value=“Отправить данные”>

<iframe name=“process” id=“process” width=“0″ height=“0″ style=“visibility: hidden”></iframe>

<div id=“alerts”></div>

Second part:

<?php
/*

Checking the received data and found errors add to the variable $alerts – for example:

$alerts.=”Error1<br />”;
$alerts.=”
Error2<br />”;
и так далее.

Depending on the outcome of displaying a message <div id=”alerts”></div> if all is ok  we resend our information to  “addmess.php”

*/

print ‘<script type=”text/javascript”>’.“n”;
print ‘//<![CDATA['."n";
if ($alerts)
{
print "top.document.getElementById('alerts').innerHTML='".$alerts."<br />';"."n";
}
else
{
print "top.document.getElementById('alerts').innerHTML='all is great !<br /><br />';"."n";
print "top.document.getElementById('urltosend').action='addmess.php';"."n";
print "top.document.forms['addform'].target=’_top’;”.“n”;
print “top.document.forms['addform'].submit();”.“n”;
}
print ‘//]]>’.“n”;
print ‘</script>’.“n”;

Just simple example  javascript and php ;)