title: before form submit call function javascript
body: <p>My program manager is a QR-code in php. I have my list of QR-codes and have (among other options) the option to delete the QR-code. When I click delete, I want to bring up a confirmation message in javascript. When I click save, I do not need confirmation.</p>
  
  <p>My form:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data"&gt;
      (...)
      &lt;input type="submit" name="save_edit" value="SAVE" /&gt;
      &lt;input type="submit" name="delete" value="Delete QR-code" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>if(isset($_POST['delete']))
  {
      $id = $_SESSION['tmp_id'];
      $query = mysql_query("SELECT name_file FROM $tbl_query WHERE id='$id'");
      if(mysql_num_rows($query) &gt; 0)
      {
          while($row = mysql_fetch_array($query))
          {
              $result = mysql_query("DELETE FROM $tbl_query WHERE id='$id'");
              unlink("img_qr/".$row["name_file"]);
              if($result)
              {
                  $_SESSION['alert_type']=1;
                  $_SESSION['msg_alerr']= "QR-code delete!";
              }
              else
              {
                  $_SESSION['alert_type']=-1;
                  $_SESSION['msg_alert']= "Error!";
              }
          }
      }
  }
  </code></pre>
  
  <p>I tried javascript but it doesn't work:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function confirm() {
          var r=confirm('Are you sure you want to delete??');
          if (r==true)
          {
              //delete file...
          }   
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to see a confirmation window before deleting.</p>