title: JS function with PHP vars onclick in <a> tag is not working
body: <p>The following code is in a single PHP file:</p>
  
  <pre><code>&lt;head&gt;
  &lt;script type="text/javascript" src="jquery.js"&gt;
  function pipeDelete(topicid, msgid, action) {
    if (topicid == 0) {
      var ans = confirm("Delete the topic?");
    } else {
      var ans = confirm("Delete this comment?");
    }
    if (ans) {
      var dest = 'msg_transact.php';
    $.post(dest, {topicid:topicid, msgid:msgid, action:action}, function() {
      $("#" + msgid).hide("slow");
            });
    }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;?php
  // some code, $row['topic_id'] and $row['msg_id'] are integers
  while ($row = mysql_fetch_assoc($result)) {
    // some code
    echo '&lt;div id="' . $row['msg_id'] . '"&gt;';
    $deletelink = '&lt;a href="#" onclick="pipeDelete(\'' . $row['topic_id'] .
      '\', \'' . $row['msg_id'] . '\', \'deletepost\')"&gt;Delete&lt;/a&gt;';
    // some code
    echo $deletelink;
    echo '&lt;/div&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>The problem is, when I click on the "Delete" link, the page just reloads ('#' is appended at the end of the URL) and nothing happens. The onclick event does not run and the function is not called. I don't think jquery or <em>// some code</em> interferes because for that to happen I should at least get the combo box isn't it?</p>
  
  <p>Whats the problem that is stopping the onclick event on calling the JS function?</p>
  
  <p>SOLUTION: Write 2 separate script tags - one for jquery src and other for js code.
  <code>&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;/* javascript code */&lt;/script&gt;</code></p>