So I have a table where when executed the table loops through the data and will insert the row of values into the DB. At the moment I am using a basic insert statement (I know about SQL injection is very temp). What I am having trouble with is at the moment I am hard coding the position of the index in the array. As you can imagine this only works for the first row. If I have two+ rows the next row values won’t be the same index. So what I am trying to though is instead of hard coding a million insert statements the table when it loops and logs the values on the UI it should insert it back into the Table at the same exact place no matter how many rows there are in the table. So instead of getInput[3].value it should be getInput[index position of whatever input it came from].value
var getInput = document.querySelectorAll(".vcheck");
for (var i = 0; i < getInput.length; i++)
console.log(getInput[i].id, " => Input", i, " = ", getInput[i].value);
DB(INSERT INTO TABLE(GENERIC_NAME, GENERIC_NAME2, etc) VALUES ('" + getInput[1].value + "', '" + getInput[2].value + "', etc))
Goal is it to be something like this
var getInput = document.querySelectorAll(".vcheck");
for (var i = 0; i < getInput.length; i++)
console.log(getInput[i].id, " => Input", i, " = ", getInput[i].value);
DB(INSERT INTO TABLE(GENERIC_NAME, GENERIC_NAME2, etc) VALUES ('" + getInput[(position in the table)].value + "', '" + getInput[position in the table].value + "', etc))
2
Answers
use Array.from to convert the list returned by querySelectorAll and use map method to extract values from each input.
Hope this will solve your issue