Colleagues,
I have a code snippet where clicking the Add fields button, I can add and send to the database.
Inthepreview,I'mbringingthedataasfollows:
<?php$sql=mysqli_query($this->conexao,"SELECT * FROM produtos WHERE IDProdutos = '".$idProdutos."';");
$visualizar = "<table border=\"0\">";
while($jmTamanhos = mysqli_fetch_object($sql)){
if($jmTamanhos->Tamanho != ""){
$visualizar .= "<tr class='linhas'>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Tamanho[]\" class=\"form-control\" placeholder=\"Tamanho\" value='".$jmTamanhos->Tamanho."'></td>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Estoque[]\" class=\"form-control pull-left\" placeholder=\"Estoque\" value='".$jmTamanhos->Estoque."'></td>
<td style=\"padding: 5px\"><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 .= "</table>";
return $visualizar;
}
?>
So far so good. It returns me:
Sofarsogood,buthowwouldIdothatbyclickingRemove,headingtotheexcludepage?Itriedthecodebelow,butIcannot.Hereisthecode:
<scripttype="text/javascript">
$(function () {
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").val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
$(".removerCampo").click(function () {
$.post("excluir-tamanhos.php", $("#excluirCampos").serialize(), function(response) {
alert('aqui 2');
$('#success').html(response);
removeCampo();
});
return false;
});
});
</script>