title: How to use alert message box using Ajax in PHP without page refresh?
body: <p>I have my PHP code here together with the design and its back end process. What is the correct syntax in using <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" rel="nofollow">Ajax</a> for using alert message that pops up when the 'createpassword' and 'confirmpassword' does not match when the user inputs a data.</p>
  
  <p>I tried using the JavaScript type of alert box, but it refreshes the form whenever the user inputs a password. I want it to just display an alert box, and it won't refresh the page. Does anyone have any ideas?</p>
  
  <p>This is my PHP design:</p>
  
  <pre><code>&lt;?php
      $MonthArray = array(
          1=&gt;"January",
          2=&gt; "February",
          3=&gt; "March",
          4=&gt; "April",
          5=&gt; "May",
          6=&gt; "June",
          7=&gt; "July",
          8=&gt; "August",
          9=&gt; "September",
          10=&gt; "October",
          11=&gt; "November",
          12=&gt; "December",
      );
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Sign up&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="container"&gt;
          &lt;div id="signup"&gt;
              &lt;form action="SignupProcess.php" method="POST"&gt;
                  &lt;!-- Complete Name --&gt;
                  &lt;div class="Name"&gt;
                      &lt;label&gt;&lt;span style="font-weight:bold"&gt;Name&lt;/span&gt;&lt;/label&gt;
                      &lt;br&gt;
                      &lt;input type="text" name="firstname" size="15" placeholder="First" required&gt;
                      &lt;input type="text" name="lastname" size="15" placeholder="Last" required&gt;
                  &lt;/div&gt;
                  &lt;br&gt;
  
                  &lt;!-- Username --&gt;
                  &lt;div class="Username"&gt;
                      &lt;label&gt;&lt;span style="font-weight:bold"&gt;Choose your username&lt;/span&gt;&lt;/label&gt;&lt;br&gt;
                      &lt;input type="text" name="username" size="35" required&gt;
                  &lt;/div&gt;
                  &lt;br&gt;
  
                  &lt;!-- Password --&gt;
                  &lt;div class="Password"&gt;
                      &lt;label&gt;&lt;span style="font-weight:bold"&gt;Create a password&lt;/span&gt;&lt;/label&gt;&lt;br&gt;
                      &lt;input type="password" name="createpassword" size="35" required&gt;
                      &lt;br&gt;&lt;br&gt;
  
                      &lt;label&gt;&lt;span style="font-weight:bold"&gt;Confirm your password&lt;/span&gt;&lt;/label&gt;&lt;br&gt;
                      &lt;input type="password" name="confirmpassword" size="35" required&gt;
                  &lt;/div&gt;
                  &lt;br&gt;
  
                  &lt;!-- Birthdate --&gt;
                  &lt;div class="Birthdate"&gt;
                      &lt;select name="month" required&gt;
                          &lt;option disabled selected&gt;Month&lt;/option&gt;
                          &lt;?php foreach($MonthArray as $monthkey =&gt; $value) { ?&gt;
                              &lt;option value="&lt;?php echo $monthkey ?&gt;"&gt;&lt;?php echo $value ?&gt;&lt;/option&gt;
                          &lt;?php }?&gt;
                      &lt;/select&gt;
  
                      &lt;input type="text" name="day" placeholder="Day" size="5" required&gt;
  
                      &lt;select name="year" required&gt;
                          &lt;?php
                              foreach(range(1990, (int)date("Y")) as $year) {
                                  echo "\t&lt;option value='".$year."'&gt;".$year."&lt;/option&gt;\n\r";
                                  rsort($year);
                              }
                          ?&gt;
                      &lt;/select&gt;
                  &lt;/div&gt;
  
                  &lt;!-- Buttons --&gt;
                  &lt;div class="Buttons"&gt;
                      &lt;input type="submit" id="signup" name="signupsubmit"&gt;
                      &lt;input type="reset" id="reset" name="signupreset"&gt;
                  &lt;/div&gt;
  
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And its PHP process:</p>
  
  <pre><code>&lt;?php
      include("CreateConnection.php");
  
      // Get values from form Signup.php file
      $FirstName = mysqli_real_escape_string($connect, $_POST['firstname']);
      $LastName = mysqli_real_escape_string($connect, $_POST['lastname']);
      $Username = mysqli_real_escape_string($connect, $_POST['username']);
      $CreatePassword = mysqli_real_escape_string($connect, $_POST['createpassword']);
      $ConfirmPassword = mysqli_real_escape_string($connect, $_POST['confirmpassword']);
      $Month = mysqli_real_escape_string($connect, $_POST['month']);
      $Day = mysqli_real_escape_string($connect, $_POST['day']);
      $Year = mysqli_real_escape_string($connect, $_POST['year']);
  
      // Removes back slashes in input
      $FirstName = stripcslashes($FirstName);
      $LastName = stripcslashes($LastName);
      $Username = stripcslashes($Username);
      $CreatePassword = stripcslashes($CreatePassword);
      $ConfirmPassword = stripcslashes($ConfirmPassword);
      $Month = stripcslashes($Month);
      $Day = stripcslashes($Day);
      $Year = stripcslashes($Year);
  
      if($CreatePassword != $ConfirmPassword)
      {
          echo "&lt;script type='text/javascript'&gt;alert('Password does not match please check.');&lt;/script&gt; ";
          echo "&lt;script&gt;setTimeout(\"location.href = 'Signup.php'\", 0)&lt;/script&gt;";
      }
      else
      {
          // Query Insert into tablereminders
          $query = mysqli_query($connect, "INSERT INTO `tablereminders`(`username`, `password`, `firstname`, `lastname`, `Month`, `Day`, `Year`)
          VALUES ('$Username','$ConfirmPassword','$FirstName','$LastName','$Month','$Day','$Year')");
      }
  
      // Error connection and query
      if(mysqli_query($connect, $query))
      {
          echo "New record created successfully";
          echo "&lt;script&gt;setTimeout(\"location.href = 'LoginReminder.php'\", 500)&lt;/script&gt;";
      }
  ?&gt;
  </code></pre>
  
  <p>This code here is where I will display an alert box without page refresh.</p>
  
  <pre><code>if($CreatePassword != $ConfirmPassword)
  {
      echo "&lt;script type='text/javascript'&gt;alert('Password does not match please check.');&lt;/script&gt; ";
      echo "&lt;script&gt;setTimeout(\"location.href = 'Signup.php'\", 0)&lt;/script&gt;";
  }
  </code></pre>
  
  <p>I want to put an Ajax request in my SignupProcess.php. Is it okay to call the form function externally?</p>