Get html array value with JavaScript

0

In the code below I get the values stored in several <textarea> with the use of the each function. But I would like to do the same in a similar way, using a for .

Can I get these values by scanning with for , how should I do it?

$("textarea[name='arraytextArea[]']:not(:first)").each(function () {
   alert($(this).val());
});
    
asked by anonymous 31.01.2018 / 19:22

1 answer

1

Yes it is possible, you can do it as follows:

var textarea = document.getElementsByName("arraytextArea[]");

//Caso não queira o primeiro textarea basta iniciar a variavel i com 1:
for(i=1;i<textarea.length;i++){
  console.log(textarea[i]);
}
<textarea name="arraytextArea[]" id="txt1">AAA</textarea>
<textarea name="arraytextArea[]" id="txt2">BBB</textarea>
<textarea name="arraytextArea[]" id="txt3">CCC</textarea>
    
31.01.2018 / 19:35