I assumed what your difficulty is to update the HTML table, not the table in the database.
You can do something like this:
HTML:
<table>
<tr class='linha' data-id="1">
<td>Linha 1</td>
<td class='coluna'>Não</td>
</tr>
<tr class='linha' data-id="2">
<td>Linha 2</td>
<td class='coluna'>Não</td>
</tr>
<tr class='linha' data-id="3">
<td>Linha 3</td>
<td class='coluna'>Não</td>
</tr>
<tr class='linha' data-id="4">
<td>Linha 4</td>
<td class='coluna'>Não</td>
</tr>
</table>
The attribute data-id
contains the id
referring to that line in the database.
Javascript/jQuery:
$(".linha").click(function() {
$(this)
.children(".coluna")
.html("Atualizado: " + $(this).data("id"));
});
The function $(this).data("id")
above returns the data-id
of that line. You will use this in your AJAX request.
The $(this).children(".coluna")
is to get the specific column of that row.
See this example in Jsfiddle.
You can change this to make everything happen by clicking the column or an image inside it if you want. (Use $(this).parents(".minha-classe")
to get a parent tag if necessary).
Read here about Unobtrusive Javascript.
Update what exactly? I don’t understand.
– bfavaretto
From what I understand, in the file
change_01.php
, you will have to make aUPDATE
at the bank, using the id and value information sent by ajax...– Felipe Avelar
I think the "table" you refer to is an HTML table... The question is ambiguous, basic information about what you are doing and what or how you intend to do it is missing.
– Daniel Omine
Welcome to Stack Overflow! If you can explain better the problem you have in particular and, if possible, show code you have done where this problem is. Your question is too broad, see Help Center How to Ask.
– Jorge B.
@user8828 Edit the question by making it clear what you really want. Mainly inform if the table you refer to is an HTML table or server database table.
– user7261