?
Solved

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

Posted on 2012-03-16
2
Medium Priority
?
265 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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

770 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