I have this Jquery function that enables an input for the user to edit a form, when editing and clicking 'Enter' I want to save the change made in the database, without submitting the form. >
- My JQuery function
$(function () {
$(".nr_ordem_exibicao").click(function () {
var id_combo = $(this).closest('tr').find('.id_combo').text() // guardo o id do combo referente a linha clicada na tabela;
var nr_ordem_exibicao = $(this).text();
$(this).html("<input type='text' style='width: 50px;' value='" + nr_ordem_exibicao + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
var novo_nr_ordem_exibicao = $(this).val();
$(this).parent().text(novo_nr_ordem_exibicao);
$.ajax({
type: "post",
url: "controllers/CombosController.php",
data: {
'id_combo': id_combo,
'nr_ordem_exibicao': novo_nr_ordem_exibicao
}
});
}
});
$(this).children().first().blur(function(){
$(this).parent().text(nr_ordem_exibicao);
});
});
});
- My Action on the Controller
public function updateOrdemExibicao(){
$comboModel = new comboModel();
$data = array(
'nr_ordem_exibicao' => $_POST['nr_ordem_exibicao']
);
$id_combo = $_POST['id_combo'];
$comboModel ->updateOrdemExibicao($data,'id_combo = ' . $id_combo);
}
- My Model
public function updateOrdemExibicao($data, $id_combo)
{
return $this ->update($data, 'id_combo =' .$id_combo);
}