2
I’m trying to update my table using javascript so I don’t have to leave the screen every time I turn off a field, my table:
The button I used in PHP but went to another page:
<td class="center">
<?php echo"<a class='btn btn-danger' href='update_produto.php?ID=$id'>Inativar</a>";?>
</td>
My button:
<button id='botao-olho' onclick='myFunction()'>Inativar</button>"
Here is the script for the update
<script type="text/javascript">
var btn_olho = $("#botao-olho");
btn_olho.on("click", function(){
$.ajax({
url: "update_produto.php",
type:"html",
dataType: "GET",
data: {id: <?php echo $id ?>}
}).done(function(retorno){
});
});
here the update:
$id = $_GET['ID'];
$estado = 'Inativo';
$sql = "UPDATE MASTER_COLETORES SET ESTADO = '$estado' WHERE ID = $id";
$stmt = oci_parse($conexao, $sql);
$result = oci_execute($stmt);
I click the button and nothing happens :T
Every button has the same
id='botao-olho'
? If yes, it’s wrong, it should beclass='botao-olho'
.– Sam
That one
<?php echo $id ?>
seems wrong to me too. Theid
on the date of Ajax should be dynamic according to the button clicked.– Sam
I switched to class and did not change anything...the id comes from mysql that I use to popular table
– Ricardo
What is this function:
onclick='myFunction()'
?– Sam
I do not understand javascript, as I saw the on click on the script, I put inside the button, no need?
– Ricardo
No need. Where the HTML
id
you want to send?– Sam
I edited the question with the button that works with php
– Ricardo
Let’s go continue this discussion in chat.
– Sam