How to assign response from AJAX's call to appropriate checkbox?

Hi Experts,

How to assign response from AJAX's call to appropriate checkbox?

var query = $.ajax({
	type: "POST",
	cache: false,
	url: "<?php echo site_url('/test/update'); ?>",
	data: { mytext: mytext },
	dataType: 'json',
	success: function(theresponse) {
		// HOW TO FIND CHECKBOX WITH THEN update the row with theresponse.value
	error: function() {
		$("#response").html("AJAX request failed.");

<div id="page">		
	<p id="response"></p>
<table id="dataTable" width="350px" border="0">
<tr><td><INPUT type='checkbox' value='productid1' name='chk[]' class='chk'/></td><td>ProductID to update 1</td></tr>
<tr><td><INPUT type='checkbox' value='productid2' name='chk[]' class='chk'/></td><td>ProductID to update 2</td></tr>
<tr><td><INPUT type='checkbox' value='productid3' name='chk[]' class='chk'/></td><td>ProductID to update 3</td></tr>

Open in new window

For example how to update checkbox with id: productid2?

Thanks before.
Who is Participating?
ansudhindraConnect With a Mentor Commented:
check this..

is this what you are looking for??
if not you have to provide id attribute for each dom element and then you can do with


for example: if is "c2" then you should have in your HTML or DOM
<input type="cehckbox" name="chk[]" id="c2" value="productidn" class="chk" />
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.