I have a code where the client clicks the button, it will activate or not a user, and of course, change the status in the database. So far so good. However, the code has two buttons, On and Off, and the Disable button is initially hidden by default. See below:
$('button#btn-cancelar').hide();
So in PHP I did it this way:
if($jmVagas->StatusVagas == 'A'){
$botao = "$('button#btn-cancelar').hide();";
}if($jmVagas->StatusVagas == 'N'){
$botao = "$('button#btn-salvar').hide();";
}
But when you click the button, it changes the status in the bank correctly, but the view appears the same in both. I'll post the code for you:
JQuery:
<script type="text/javascript">
$(document).ready(function(){
// $('button#btn-cancelar').hide();
<?php
echo $visualizarVagas[1];
?>
$('button#btn-salvar').click(function(){
$('button#btn-salvar').hide();
$('button#btn-cancelar').show();
var valor = $(this).attr('value');
$('button#btn-cancelar').text("Desativado").attr({
title:"Desativado"
});
jQuery.ajax({
url : "alterar.php?v=N&k="+valor,
dataType : 'json',
async : false,
success : function(msg) {
}
});
});
$('button#btn-cancelar').click(function(){
$('button#btn-salvar').show();
$('button#btn-cancelar').hide();
var valor = $(this).attr('value');
$('button#btn-salvar').text("Ativado").attr({
title:"Ativado"
});
jQuery.ajax({
url : "alterar.php?v=A&k="+valor,
dataType : 'json',
async : false,
success : function(msg) {
}
});
});
});
</script>
PHP:
while(...){
if($jmVagas->StatusVagas == 'A'){
$botao = "$('button#btn-cancelar').hide();";
}if($jmVagas->StatusVagas == 'N'){
$botao = "$('button#btn-salvar').hide();";
}
$listar .= "<button class=\"btn btn-xs btn-primary\" id=\"btn-salvar\" value=\"".$jmVagas->IdVagas."\" title=\"Ativado\">Ativado</button>";
$listar .= "<button class=\"btn btn-xs btn-danger\" id=\"btn-cancelar\" value=\"".$jmVagas->IdVagas."\" title=\"Desativado\">Desativado</button>";
}