title: How can I stop onload event?
body: <p>I am using Ajax and jQuery to get output on click event of submit button</p>
  
  <p>I have two files</p>
  
  <ol>
  <li><code>Index.php</code> (contains the jQuery &amp; Ajax Code)</li>
  <li><code>actionfile.php</code> (A php file that extracts the data sent by Ajax code in <code>Index.php</code> and stores the data in a file)</li>
  </ol>
  
  <p>Index.php:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form name="myform" method="post"&gt;
  &lt;input type="text" name="txt1" id="txt1" value="121212"/&gt;
  &lt;input type="submit" value="submit" id="submit" name="submit" /&gt;
  &lt;/form&gt;
  
  &lt;script&gt; 
  $("#submit").click(function() {
      var txt =document.getElementById('txt1').value;  //textbox value
      alert(txt);
      var txt1 = "txt1="+txt;
      alert(txt1);
      $.ajax({
              type: "POST",
              url: "actionfile.php",
              data:txt1,
              success: function() {
                 alert("success");
              }
          });
      });
  &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And actionfile.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
      error_reporting(E_ALL);
      $map=$_POST['txt1'];
      $fp=fopen("file.txt","w");
      fwrite($fp,$map);
      fclose($fp);
  ?&gt;
  </code></pre>
  
  <p>The problem is, if I remove the piece of code <code>$("#submit").click(function()</code> ajax works fine, meaning it submits data when the page is loaded (provided I give default value in textbox). When I keep the code <code>$("#submit").click(function()</code> intact, the function is called only when submit button is pressed but in this case AJAX fails.</p>
  
  <p>The code is available on <a href="http://www.code.guru99.com/kishore" rel="nofollow">http://www.code.guru99.com/kishore</a></p>
  
  <p>What is causing this issue?</p>