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 {
7 Years
Discussion Span
Last Post by essential

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"
<html id="html40L" lang="en">
<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">

<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!" );
     return false;
// -->
<div id="main">
<form id="form1" action="#" method="post" onsubmit="return validate( this );">
Test Field : <input type="text" id="txt" name="txt" value=""><br><br>

<input type="submit" value="s u b m i t">
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.