If i wan the alert appear in the same page on the index want code should i write??

I write the code but when i click submit the alert show on next page not the index page so how??

Below is my code:-

if($from == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent, You have not entered a Name, please go back fill up and try again!!')</script>";}
else {

Just put it on the page in, where you need those alert.

Here's a quick demo that you can try :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html id="html40L" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Window-target" content="_top">
<title>Free Live Help!</title>
<style type="text/css">
<!--

-->
</style>
<script type="text/javascript">
<!--
var validate = function( form ) {
   if ( form.txt.value ) {
   alert( "Thank you for visiting my site");
   return true; 
   } alert( "Please fill up some text!" );
     form.txt.focus();
     return false;
};
// -->
</script>
</head>
<body>
<div id="main">
<form id="form1" action="#" method="post" onsubmit="return validate( this );">
<div>
Test Field : <input type="text" id="txt" name="txt" value=""><br><br>

<input type="submit" value="s u b m i t">
</div>
</form>
</div>
</body>
</html>
This article has been dead for over six months. Start a new discussion instead.