Ali Ali - 6 months ago 45
Javascript Question

change content of next td by using jquery

I have a table that in each row of that there is a combobox in a td tag, I want when combobox changed then content of next td changes

I wrote this code but it does not work:

$(document).ready(function () {
$('#table tr td').find('.combobox').change(function () {
var myvar=$(this).val();
$.post("./data.php", {
p_array : myvar,
}, function(data) {
$(this).parent().next('td').html(data);
});
});
});


table structure:

<table>
<tr>
<td>
<select class="combobox">
<option>
select something
</option>
</select>
<td>
<td>must be changed</td>
<tr>
</table>


what is the problem?

Answer

this in post is other thing than this before post... the simplest solution would be:

$(document).ready(function () {
    $('#table tr td').find('.combobox').change(function () {
        var myvar=$(this).val();
        var xthis = this;
        $.post("./data.php", {
                    p_array : myvar,
                    }, function(data) {
                        $(xthis).parent().next('td').html(data);
                });
    });
});
Comments