-1
How do I make sure that when I click the remove button and activate the removeCampo() function, it is called the page that would delete this directly from the mysql database? I only need the part of Jquery for this, because PHP and Mysql I know how to do. See below:
I’m bringing this information from the database as follows:
....
while($jmTamanhos = mysqli_fetch_object($sql)){
$visualizar .= "<tr class='linhas'>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Cores[]\" class=\"tamanhos form-control\" placeholder=\"Cor do Produto\" value='".$jmTamanhos->Cores."'></td>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Tamanho[]\" class=\"form-control pull-left\" placeholder=\"Tamanho\" value='".$jmTamanhos->Tamanho."'></td>
<td style=\"padding: 5px\"><input type=\"number\" name=\"EstoqueProd[]\" class=\"form-control pull-left\" placeholder=\"Estoque\" min=\"1\" value='".$jmTamanhos->Estoque."'></td>
<td style=\"padding: 5px\">
<input type='hidden' name='IDEstoques[]' value='".$jmTamanhos->IDEstoques."'>
<button type=\"button\" class=\"removerCampo btn btn-danger\" title=\"Remover linha\"><i class=\"fa fa-minus-square\" aria-hidden=\"true\"></i> Remover</button>
</td>
</tr>";
}
$visualizar .= " <tr><td colspan=\"3\"><button type=\"button\" class=\"adicionarCampo btn btn-primary\" title=\"Adicionar item\"><i class=\"fa fa-plus-square\" aria-hidden=\"true\"></i> Adicionar mais tamanhos</button></td></tr>";
....
And the Jquery:
<script type="text/javascript">
$(function () {
removeCampo();
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find('input[type="text"]').val("");
novoCampo.find('select').val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
});
</script>
It doesn’t. Javascript runs in the browser and it is impossible to access the database directly through it (thank goodness! ). You’ll have to make an HTTP request and treat the server deletion with its language (apparently it’s PHP)
– Jéf Bueno
Hello LINQ, actually it is not delete the data by javascript or jquery, but rather when clicking the button and enable the function removeCampo(), is called the page that would delete, which in the case is in PHP.
– user24136
Hello LINQ, I adjusted my post. Sorry, I had not been clear in my doubt.
– user24136