title: How can I made a dynamic checkbox alert with onclick function?
body: <p>I have the following function below that creates multiple check boxes in a table. 
  Problem: I cannot get the value for each box checked.   </p>
  
  <pre><code>function createRoutesTable(result)
      {
          var length = result.jsonList.length;
          var tablecontents = "";
          console.log(length);
          tablecontents ="&lt;table&gt;";
          for(var i = 0; i &lt; length; i++)
          {
              tablecontents += "&lt;tr&gt;"
              tablecontents += "&lt;td&gt;&lt;input type='checkbox' id='checkbox_"+ i + "' value='" + result.jsonList[i].Id +"' onclick = 'createAlerts()'&gt;&lt;td&gt;"
              tablecontents += "&lt;/tr&gt;"
          }
          tablecontents +="&lt;/table&gt;";
          document.getElementById("tablespace").innerHTML = tablecontents;
  
      }
  </code></pre>
  
  <p>Here is my function below: </p>
  
  <pre><code>function createAlerts()
  {
  
       if( $('#checkbox_1').is(':checked'))
       {
           alert($(this).val());
       }
  
  }
  </code></pre>
  
  <p>This will work for the first box, but I need a way for everytime I click any box, it will grab the appropriate value. I really don't want to have to write brittle code and write this if statement for each checkbox I created. That's really bad. </p>
  
  <p>Put another way, no matter if I click checkbox_3 or checkbox_6, I will get the value for that checkbox. I thought about trying it this <a href="http://jsfiddle.net/heten/19/" rel="nofollow">way</a>, but I need this to work with a function when I use "onclick", so I got stuck. </p>
  
  <p>Please help. I will give + rep where I can on responses to this question. </p>