Solved

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

Posted on 2012-03-16
2
261 Views
Last Modified: 2012-06-21
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) {
		$("#response").html(theresponse.message);
		
		// HOW TO FIND CHECKBOX WITH theresponse.id THEN update the row with theresponse.value
		
		
	},
	error: function() {
		$("#response").html("AJAX request failed.");
	}
});

<div id="page">		
	<p id="response"></p>
</div>
<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>
</table>

Open in new window


For example how to update checkbox with id: productid2?

Thanks before.
0
Comment
Question by:jimmycdinata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 500 total points
ID: 37728329
check this..

http://jsfiddle.net/Sudhindra/tackc/

is this what you are looking for??
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37728335
if not you have to provide id attribute for each dom element and then you can do with

$('#'+resid).parent().next().html(resval);

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question