Checkbox in a dynamic table with dynamic input fields
<p>I have a table with dynamic values and hidden input fields and dynamic  checkbox. Checkboxes have same class names. When i click on a particular checkbox i want the input values from that particluar row should be sent to ajax.</p>

<p>Below is the code for dynamic table,</p>

<pre><code>&lt;table  id="table"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th &gt;Sl.no&lt;/th&gt;
&lt;th &gt;Owner Name&lt;/th&gt;
&lt;th &gt;Contact Number&lt;/th&gt;
&lt;th class="text-center" data-title="Action"&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody id="responsive-table-body"&gt;
&lt;?php 
$owner=mysql_query("select id,tmp_id,name,phone,activate from pgowner where active='1'");
if(mysql_num_rows($owner)){
$i=0;
while($owner1=mysql_fetch_array($owner)){
$id=$owner1['tmp_id'];
?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span class="label label-default"&gt;&lt;?php echo ++$i; ?&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href='viewprofile?id=&lt;?php echo $id; ?&gt;' target='_blank' style='color:blue;text-decoration:underline;'&gt;&lt;?php echo $owner1['name']; ?&gt;&lt;/a&gt;
&lt;input type="hidden" name="ownerid" value="&lt;?php echo $owner1['tmp_id']; ?&gt;" id="ownerid" /&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;?php echo $owner1['phone']; ?&gt;         
&lt;/td&gt;
&lt;td&gt;
&lt;input type="checkbox" name="activate[]" class="activate" id="activate" /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?php }  }
    ?&gt;                
&lt;/tbody&gt;
&lt;/table&gt;    
</code></pre>

<p>Here's the ajax code to fetch the value from the row in which checkbox is checked.</p>

<pre><code>&lt;script type="text/javascript"&gt;

$(document).ready(function(){
$('#activate').click(function(){

var ownerid=$('#ownerid').val();
var myonoffswitch=$('#activate').val();

if ($("#activate:checked").length == 0)
{
var a='0';
}
else
{
var a="1";
}
$.ajax({
type: "POST",
url: "profileactivation",
data: "value="+a +"&amp;ownerid="+ownerid,
success: function(html){
alert("Successfully Done");
}
});
});
});
&lt;/script&gt;
</code></pre>

<p>I am not able to fetch the input value from the row in which checkbox is checked. Please help.</p>

<p>Generated HTML looks like this,</p>

<pre><code>&lt;table id="table" &gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th &gt;Sl.no&lt;/th&gt;
&lt;th &gt;Owner Name&lt;/th&gt;
&lt;th &gt;Contact Number&lt;/th&gt;
&lt;th &gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody id="responsive-table-body"&gt;
&lt;tr &gt;
&lt;td &gt;&lt;span class="label label-default"&gt;1&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="viewprofile?id=EdXzrq" target="_blank" style="color:blue;text-decoration:underline;"&gt;Name1&lt;/a&gt;
&lt;input type="hidden" name="ownerid" value="EdXzrq" id="ownerid"&gt;
&lt;/td&gt;
&lt;td&gt;
9731269342          
&lt;/td&gt;
&lt;td&gt;
&lt;input type="checkbox" name="activate[]" class="activate" id="activate"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr &gt;
&lt;td &gt;&lt;span class="label label-default"&gt;2&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="viewprofile?id=RowMpg" target="_blank" style="color:blue;text-decoration:underline;"&gt;Name2&lt;/a&gt;
&lt;input type="hidden" name="ownerid" value="RowMpg" id="ownerid"&gt;
&lt;/td&gt;
&lt;td&gt;
7760807087          
&lt;/td&gt;
&lt;td&gt;
&lt;input type="checkbox" name="activate[]" class="activate" id="activate"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</code></pre>