Take html array value with Javascript

Asked

Viewed 1,078 times

0

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

It is possible to pick up these values by scanning with a for, how should I do?

$("textarea[name='arraytextArea[]']:not(:first)").each(function () {
   alert($(this).val());
});

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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.