I am collecting data in inputs with a each
, when I try to add it in a variable it tells me that the name is not defined, it seems I have a syntax error.
function guardar_testimonio(){
$("#infotestis").each(function(){
var nombre = $("#infotestis").parent().find("input").eq(0).val();
var testimoniouno= $("#infotestis").parent().find("input").eq(1).val();
var testimoniodos= $("#infotestis").parent().find("input").eq(2).val();;
var compania= $("#infotestis").parent().find("input").eq(3).val();;
var lugar= $("#infotestis").parent().find("input").eq(4).val();;
console.log(nombre+" "+testimoniouno+" "+testimoniodos+" "+compania+" "+lugar);
});
var datos_formulario = "nombres=" + nombre;
// "&testimoniouno="+testimoniouno+ "&testimoniodos="+testimoniodos +"&compania="+ compania + "&lugar="+ lugar;
$.ajax({
type: 'POST',
url: '../dashmin/php/agregar.php',
data: datos_formulario,
dataType: 'json',
beforeSend: function (objeto) {
},
success: function (json) {
},
error: function (e) {
},
complete: function (objeto, exito, error) {
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="infotestis">
<h5>Nombre:</h5> <input class="form-control" type="text" value="Alejando Sallustro">
<h5>Testimonio:</h5> <input class="form-control" type="text" value="Una inversión acorde"><input class="form-control" type="text" value="a estos tiempos">
<h5>Compañia:</h5> <input class="form-control" type="text" value="CEO, Sallustro & Cía.">
<h5>Lugar:</h5> <input class="form-control" type="text" value="Asuncion">
<h5>Perfil:</h5> <img src="" alt="">
<button onclick="guardar_testimonio()" class="btn btn-primary">Guardar<div class="ripple-container"></div></button>
</div>