Solved

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

Posted on 2012-03-16
2
258 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now