I have a dynamic form, where you can see several textarea
, and by default, this textarea
has the same id
and the same name
, but name
is being sent as array
% (name="nomecampo[]"
).
I would like to know how I can validate all these textarea
in javascript , because I need to check if these textarea
has less than 10
The textarea
looks like this:
<textarea class="form-control txta" rows="4" name="descr_icon[]" id="descri_icon" ></textarea>
And since the form is dynamic, one, none, or several textarea
can appear like this, and I need to validate in javascript (need to be neat, I can not use jquery ) each% with% of this, but the validation is the same for all.
I found some solutions counting the index of textarea
by textarea
, but in my case name
is passing name
, so it did not work.
What I found was something like this:
function validacao(nomecampo) {
var total = document.getElementsByName(nomecampo);
for(i = 0; i < total.lenght; i++) {
if (document.getElementByName(i) < 10) {
alert('Erro');
return (false);
}
}
}
And in the function call:
<textarea name="camponome" id="camponome"></textarea>
<button onclick="validacao('camponome')"></button>
But as I said, this did not work in my case because I pass array
to name
( array
).
Would anyone know of a possible solution?