-3
I am trying to update using a data-table, this data-table is by default disabled for editing, and on each line has a button named 'Edit' when clicking the button on the line and enabled for editing, and the name of the button changes to 'Save'. So far so good, but when clicking the 'Save' button you should take the edited values to do the update, return the name of the button to 'Edit', and disable the edit again.
js
function botaoEditar(button_edit){
if($(button_edit).parents("tr").find('button span').text() == "Editar"){
var _row = null;
_row = $(button_edit).parents("tr");
var cols = _row.children("td");
$(button_edit).parents("tr").find('input').prop('readonly', false);
alert($("input[name='cabo']").val());
$(button_edit).parents("tr").find('button').removeClass('btn_editar');
$(button_edit).parents("tr").find('button').addClass('btn_salvar');
$(button_edit).parents("tr").find('button span').text('Salvar');
} else{
var _row = null;
_row = $(button_edit).parents("tr");
$(button_edit).parents("tr").find('input').prop('readonly', true);
alert($("input[name='cabo']").val());
$(button_edit).parents("tr").find('button').removeClass('btn_salvar');
$(button_edit).parents("tr").find('button').addClass('btn_editar');
$(button_edit).parents("tr").find('button span').text('Editar');
}
Obs. the Alert() in both if conditions returns the same value that comes from the database.
HTML /php
foreach($listaRamais as $listRamal){
echo"
<tr>
<td><input typ='text' id='cabo' name='cabo' maxlength='5'style='width:100%;text-align: center;' readonly='readonly' value='".$listRamal['cabo']."'/></td>
<td><input typ='text' name='par' maxlength='5'style='width:100%;text-align: center;' readonly='readonly' value='".$listRamal['par']."'/></td>
<td id='ramal'><input typ='text' name='ramal' maxlength='9'style='width:100%;text-align: center;' readonly='readonly' value='".$listRamal['numero_ramal']."'/></td>
<td><input typ='text' name='setor' maxlength='30' style='width:100%;text-align: center;' readonly='readonly' value='".$listRamal['setor_ramal']."'/></td>
<td>
<button id='btn_edite' type='button' onclick='botaoEditar(this);' class='btn_editar'>
<span class='glyphicon glyphicon-edit'>Editar</span>
</button>
</td>
<td style='display:none;'>".$listRamal['id_unidade']."</td>
</tr>
";
}
Someone would tell me how to get the new values typed?
That
$("input[name='cabo']")
will always return this element<input typ='text' id='cabo' name='cabo' maxlength='5'style='width:100%;text-align: center;' readonly='readonly' value='".$listRamal['cabo']."'/>
– Augusto Vasques
Even by typing another text into the input? I thought that clicking the button again would get the new text typed. What would be the right way to do this?
– Roberto Marcos
No he searches the tree of the document.
– Augusto Vasques
please, friend, would you have an example of how I could pick up the data, typed?
– Roberto Marcos
I can even set an example, but at the moment I am helping someone else. You will have to wait a little.
– Augusto Vasques
All right Augusto, it can be later, I’m waiting. Thank you!
– Roberto Marcos