I'm trying to get by name 2 inputs
that generates by jQuery a select (that's why the counter) then make a REQUEST
in ajax with a foreach
that traverses input by input to make the save, the problem is that I get the 2 values of the input at the same time:
function guardarDescripcion() {
var inclusions1 = '';
var incCount = document.getElementsByName("inclusions1[]").length;
for(i=0;i<incCount;i++){
inclusions1 = + inclusions1 document.getElementsByName("inclusions1[]")[i].value;
}
$.ajax({
url: "ajax_save.php",
data: "&inclusions1=" + inclusions1,
type: "GET",
timeout: 10000,
success: function () {
alert("Datos guardados exitosamente");
},
error: function () {
alert("Error al guardar el opcional.");
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="inclusions1[]" class="form-control " value="TEST1" style="width: 246px; margin: 4px 0px;">
<input type="text" name="inclusions1[]" class="form-control " value="TEST2" style="width: 246px; margin: 4px 0px;">
<button type="button" onclick="guardarDescripcion();">Save</button>