1
I have a form with a input
that is created dynamically, follows below:
<tr class="linhas">
<td align="right">Inicio:</td>
<td align="left"><input name="inicio[]" class="data" type="text" value="" style="font-size: 12pt; font-weight: bold; width: 130px" /></td>
<td align="right">Término:</td>
<td align="left"><input name="termino[]" class="data" type="text" value="" style="font-size: 12pt; font-weight: bold; width: 130px" /> <a href="#" class="removerCampo" title="Remover linha"><img src="imagens/exc_btn.png" border="0" /></a></td>
</tr>
<script type="text/javascript">
$(document).ready(function() {
$(".data").mask("99/99/9999");
$(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();
$(".data").mask("99/99/9999");
});
});
});
the form itself works well, the problem is that I can’t get the dynamic values of the beginning and ending, follow the code:
function SalvarRegistro(){
var inicio = $("input[name='inicio[]']").val();
var termino = $("input[name='termino[]']").val();
$.ajax({
type: "POST",
dataType: "json",
url: "acao/cadastro_averbacao1.php",
data: {inicio: inicio, termino: termino},
success: function(data) {
if(data.sucesso == 0){
swal({
title: "Sucesso",
text: data.msg,
type: "success"
},
function(){
parent.location.href = parent.location.href;
});
}else{
swal({
title: "Um erro ocorreu",
text: data.msg,
type: "error"
});
}
},
failure: function() {
swal({
title: "Um erro ocorreu",
text: "Usuário não encontrado verifique o número digitado!",
type: "error"
},
function(){
parent.location.href = parent.location.href;
});
}
});
return true;
}
thank you friend had managed to serialize: var inicio = $.serialize("input[name='inicio[]']); var termino = $.serialize("input[name='termino[]']"); but this solution of yours has served me more
– opeta
If you need to ask... if you can help... I’ll help.
– Allan Andrade