title: Passing Parameters to JQuery onclick event
body: <p>I am new in Jquery, and need the correct strategy to carry out a dynamic form.</p>
  
  <p>I want to create a dynamic form. I retrieve values from database, display them as rows &amp; then for every value, the user can add as many rows as he want. below code show a loop that create a table for every value, with "customFields" ID, which is append with "$i" variable to make it unique. </p>
  
  <pre><code>// query code
  $i = 1;
   while ($row = mysql_fetch_array($sqlQ))
    {
           $var1 = $row['sid'];
           $var2 = $total_rows;
   ?&gt;
       &lt;table id="customFields&lt;?php echo $i; ?&gt;" class="box-table-a" align="left"&gt;
  
  &lt;thead&gt;
      &lt;tr&gt;
         &lt;th colspan="5" scope="col"&gt;&lt;?php echo $row['VS_NAME']; ?&gt;&lt;/th&gt;
         &lt;th  scope="col" align="Right"&gt;&lt;a href="javascript:void(0)" id="addCF&lt;?php echo $i++; ?&gt;"     &gt;Add Row&lt;/a&gt;&lt;/th&gt;
     &lt;/tr&gt;
    &lt;/thead&gt;
  
  &lt;/table&gt;
  
   }
  </code></pre>
  
  <p>Now for this code, I write the following javascript Append code.</p>
  
  <pre><code> &lt;script&gt;
   &lt;?php for ($i = 1; $i &lt;=5; $i++) { ?&gt;
       $("#addCF"+&lt;?php echo $i; ?&gt;).click(function(){
           $("#customFields&lt;?php echo $i;?&gt;").append('&lt;tr &gt;&lt;td width="13%"&gt;&lt;input type="text" name="godkant[]" class="fieldWidth" /&gt;&lt;/td&gt;&lt;td width="11%" style="background:#b5dbe6" &gt;&lt;input type="text" name="foreRengoring[]" class="fieldWidth" /&gt;&lt;/td&gt;&lt;td  width="12%" style="background:#e6b8b8"  &gt;&lt;input type="text" name="efterRengoring[]" class="fieldWidth" /&gt;&lt;/td&gt;&lt;td width="12%" style="background:#c0d498" &gt;&lt;input type="text" name="borvarden[]" class="fieldWidth" /&gt;&lt;/td&gt;&lt;td width="12%" style="background:#ffff66" &gt;&lt;input type="text" name="injust[]" class="fieldWidth" /&gt;&lt;/td&gt;&lt;td width="40%" &gt;&lt;input type="text" name="noteringar[]" class="fieldWidthNote" /&gt;&lt;/td&gt;&lt;/tr&gt;'); });
      &lt;?php } ?&gt;
   &lt;/script&gt;
  </code></pre>
  
  <p>The above code works perfectly fine. but I don't know the number of values my php while loop will return. so i need to pass two values to this javascript click event. one for the loop, and 2nd for to be displayed when we add a row. </p>
  
  <p>Questions;
  1. what is the best strategy to carry out this kind of function.
  2. can I use Jquery event handler (if i am calling it correctly - $(#id).append...) in my own function which can be called on Onclick event?</p>
  
  <p>I hope that I explain the problem correctly. 
  This question is asked many times, but I am new to Jquery, thats why i am not able to map the answers to my solution. </p>
  
  <p>need help.</p>
  
  <p>Thanks</p>