From a screen I get the ID
and the VALOR
of a group of INPUT TEXT
with the following code:
var docs = document.getElementsByName('ftp_desc');
for (var i = 0; i < docs.length; i++){
console.log('id: ' + docs[i].id + ',' + 'value: ' + docs[i].value);
}
<input id="1" name="ftp_desc" maxlength="256" placeholder="Añade una descripción" required="required" type="text">
<input id="2" name="ftp_desc" maxlength="256" placeholder="Añade una descripción" required="required" type="text">
<input id="3" name="ftp_desc" maxlength="256" placeholder="Añade una descripción" required="required" type="text">
How can I make a STRING from the array of the IDs and one of the VALUEs?
Example:
var ids = "1,2,3";
var values = "Desc1,Desc2,Desc3"
You can solve it by adding the ids and the values that you find in their respective variables, to finally have them all.
You can make use of the Object.keys() and Object.values() methods to get the values and keys of an
array
(obj) that you create and fill inside the , as well as the join()for
method to format it with a separator (, )