I'm making a form that collects data and then stores it in variables to make operations with them, but when you store them in an array and then try to pick them up they get lost somewhere or they do not get picked up with the function that calls them.
Initial position: Initial velocity: Initial acceleration: <div class="col-6">
<label for="x1">Posición inicial:</label>
<input type="text" class="form-control" placeholder="m" id="x2">
<label for="v1">Velocidad inicial:</label>
<input type="text" class="form-control" placeholder="m/s" id="v2">
<label for="a1">Aceleración inicial:</label>
<input type="text" class="form-control" placeholder="m/s2" id="a2">
</div>
And this is the javascript code
var time, position, resultados;
function obtenerDatos(){
var x1 = document.getElementById("x1").value;
var v1 = document.getElementById("v1").value;
var a1 = document.getElementById("a1").value;
var x2 = document.getElementById("x2").value;
var v2 = document.getElementById("v2").value;
var a2 = document.getElementById("a2").value;
var r = [x1, x2, v1, v2, a1, a2];
return r;
}
resultados = obtenerDatos();
var x1 = resultados[0];
var x2 = resultados[1];
var v1 = resultados[2];
var v2 = resultados[3];
var a1 = resultados[4];
var a2 = resultados[5];
My second question is whether I can separate code (in different files) from the same script that calls functions or variables from another file. The two would be called in the same HTML.
Thank you.