title: how to call jquery function after php if condition?
body: <p>I want to display jquery sweet alert after php insert query successfully executed.. but whenever i tried to call jquery function after if condition, didn't work..or alert appear for 1-2 sec before page reload for form submit and disappear immediately..it only works with button onclick method..</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="lib/sweet-alert.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="lib/sweet-alert.css"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form method="post"&gt;
    &lt;label for="name"&gt;name&lt;/label&gt;
    &lt;input type="text" name="name" id="name" /&gt;
    &lt;input type="submit" value="submit" name="submit" class="sub" id="sub" /&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;?php
     $a=mysql_connect("localhost","root","");
     $a1=mysql_select_db("test",$a);
  
    if(isset($_POST['submit']))
    {
           $name=$_POST['name'];
           $i=mysql_query("insert into student (name) values ('$name')");
      if($i)
      {
  
          echo "&lt;script&gt;a();&lt;/script&gt;";
      }
    }
   ?&gt;
  
   &lt;script type="text/javascript"&gt;
   function a(){
   swal("Here's a message!");
   };
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>