Im using Jeditable inside a table, to update a value.
function updateOwner(row, value, settings) {
var td = $(row).closest('.cvrnummer');
alert(td.html());
$.post('UserAdministration/UpdateOwners', { owner: value }, function (data) {
alert(data);
});
}
$('.editable').editable(function (value, settings) {
updateOwner(this, value, settings);
return (value);
}, {
data: " {'mona':'moma','cecilie':'cecilie','jacob':'jacob', 'morten':'morten', 'rasmus' : 'rasmus', 'selected':'mona'}",
type: 'select',
submit: 'OK'
});
The table looks like this:
<table id="userTable" class="table-autofilter table-autosort" >
<thead>
<tr>
<th>CVR-Nummer</th>
<th>Firma navn</th>
<th class="table-filterable">Tilhører</th>
<th class="table-sortable:date">Oprettet</th>
<th>Sidst online</th>
<th></th>
<th class="table-sortable:numeric table-sortable">Besvaret (%)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cvrnummer"></td>
<td></td>
<td class="editable" style="text-align: center;"></td>
<td></td>
<td></td>
<td>Se besvarelser</td>
<td>
</td>
</tr>
</tbody>
</table>
I want to pass the value inside
<td class="cvrnummer"></td>
when i use AJAX to post a value, but im not sure how to get the value. Im using:
var td = $(row).closest('.cvrnummer');
alert(td.html());
which is returning null.
How do i get the value?
You should do
var td = $(row).closest('tr').find('td.cvrnummer');
because closest()
goes up the DOM tree, while find()
goes down. You can't use prev()
because it returns just the preovious element