title: Turn Regular Javascript Into jQuery
body: <p>I have some code that involves clicking on a button and either you are logged in and you go to the next page or you are logged out and you get an alert.  I have never liked <code>onClick</code> inside HTML and so I would like to turn this around into clicking on the id and having the jQuery do its magic.  </p>
  
  <p>I understand the click function of jQuery, but I don't know how to put <code>do_bid(".$val["id"].");</code> down with the rest of the Javascript.  If I haven't given enough information or if there is an official resource for this then let me know.</p>
  
  <pre><code>&lt;li class='btn bid' onclick='do_bid(".$val["id"].");'&gt; Bid &lt;/li&gt;
  
  &lt;script&gt;
      //Some other Javascript above this
      function do_bid(aid)
      {
          var loged_in = "&lt;?= $_SESSION["BPLowbidAuction_LOGGED_IN"] ?&gt;";
          if(loged_in=="")
          {
              alert('You must log in to bid!');
          }
          else
          {
              document.location.href="item.php?id="+aid;
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong> This is the entirety of the Javascript code. I think none of the answers have worked so far because the answers don't fit the rest of my Javascript.  I hope this helps</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;
      $(document).ready(function(){
  function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero &amp;&amp; s.length &lt; 2)
  s = "0" + s;
  return "" + s + "";
  }
  function CountBack() {
  &lt;?
  for($i=0; $i&lt;$total_elements; $i++){
  echo "myTimeArray[".$i."] = myTimeArray[".$i."] + CountStepper;";
  }
  for($i=0; $i&lt;$total_elements; $i++){
  echo "secs = myTimeArray[".$i."];";
  echo "DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,1000000));";
  echo "DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));";
  echo "DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));";
  echo "DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));";
  echo "if(secs &lt; 0){
  if(document.getElementById('el_type_".$i."').value == '1'){
  document.getElementById('el_".$i."').innerHTML = FinishMessage1;
  }else{
  document.getElementById('el_".$i."').innerHTML = FinishMessage2;";
  echo "  }";
  echo "}else{";
  echo " document.getElementById('el_".$i."').innerHTML = DisplayStr;";
  echo "}";
  }
  ?&gt;
  if (CountActive) setTimeout("CountBack()", SetTimeOutPeriod);
  }
  function putspan(backcolor, forecolor, id) {
  document.write("&lt;span id='"+ id +"' style='background-color:" + backcolor + "; color:" + forecolor + "'&gt;&lt;/span&gt;");
  }
  if (typeof(BackColor)=="undefined")     BackColor = "white";
  if (typeof(ForeColor)=="undefined")     ForeColor= "black";
  if (typeof(TargetDate)=="undefined")    TargetDate = "12/31/2020 5:00 AM";
  if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%%d, %%H%%h, %%M%%m, %%S%%s.";
  if (typeof(CountActive)=="undefined")   CountActive = true;
  if (typeof(FinishMessage)=="undefined") FinishMessage = "";
  if (typeof(CountStepper)!="number")     CountStepper = -1;
  if (typeof(LeadingZero)=="undefined")   LeadingZero = true;
  CountStepper = Math.ceil(CountStepper);
  if (CountStepper == 0) CountActive = false;
  var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
  var myTimeArray = new Array();
  &lt;?  for($i=0; $i&lt;$total_elements; $i++){?&gt;
  ddiff=document.getElementById('el_sec_'+&lt;?=$i;?&gt;).value;
  myTimeArray[&lt;?=$i;?&gt;]=Number(ddiff);
  &lt;? } ?&gt;
  CountBack();
             function do_bid(aid)
      {
          var loged_in = "&lt;?= $_SESSION["BPLowbidAuction_LOGGED_IN"] ?&gt;";
          if(loged_in=="")
          {
              alert('You must log in to bid!');
          }
          else
          {
              document.location.href="item.php?id="+aid;
          }
      }
  }&lt;/script&gt;
  </code></pre>