Reputation: 65
i'm trying to place my ajax results in the td next to my drop down that calls the ajax onchange. each row has a similar id where i want the text to appear (i'm sure there is an easier way). here is what i have.
$(".select-service").on("change", function() {
var service = $(this).val();
var id = $(this).attr('id');
$.ajax({
type: "post",
url: "ajax/getServiceDesc.php",
data: {service:service},
dataType: "json",
success: function(results){
console.log(results['Description'][0].description);
ive tried using $(this).next('td') but it isn't recognizing the $(this). it comes back as undefined.
i've also tried $(id) - as i've set the drop down id above the ajax call.
the structure of the td is as follows.
var n=($('.detail tr').length-0)+1;
var tr = '<tr>'+
'<td>'+n+'</td>'+
'<td><select id="drop'+n+'" class="select-service" name="prodService[]">
<option value="">- Choose Service -</option><option value="1">- Choose
Service -</option></select></td>'+
'<td id="desc'+n+'"></td>'+
'<td><a href="#" class="remove">Delete</a></td>'+
'</tr>';
i'm trying to target the id starting with desc. the ending number matches the id of the drop id.
how would i place my result in that td
Upvotes: 0
Views: 26
Reputation: 28455
Try following
var id = $(this).attr('id').replace("drop", "desc");
Now, you can use $("#"+id)
in your function to access the element.
Upvotes: 1