I'm trying to create a two-dimensional array with dynamic data. These data are requested to the user through some inputs. The program first asks for the size of the matrix and from that, dynamic inputs are generated based on the order you chose. The problem is that I could already generate the inputs but now I do not know how to access each value and save everything in an obvious two-dimensional array.
So far I have this:
HTML:
<select id="matriz" >
<option selected>Ingrese el orden de la matriz</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<div class="" id="mostrarMatriz">
</div>
<input type="button" value="Mostrar matriz" id="btnMostrar">
And the JS:
$("#btnMostrar").hide();
$('#matriz').change(function(){
$("#btnMostrar").show();
var val = $(this).val();
var innerhtml = '';
for (var i = 0; i < val; i++) {
for (var j = 0; j < val; j++) {
innerhtml += "<input type='text' placeholder='' id='" + (j + 1) + "' name='" + (j + 1) + "' size=5>";
}
innerhtml+="<br>";
}
var display = $(this).next('#mostrarMatriz');
display.html(innerhtml);
});
Any idea how to get the values and put them in a fix? thanks in advance!