I have the following code.
Html:
<div>
<textarea name='arraytextArea[]'></textarea> <br>
<input type="radio" name="grupo1" value="Valor1"><span>Valor1</span>
<input type="radio" name="grupo1" value="Valor2"><span>Valor2</span>
<input type="radio" name="grupo1" value="Valor3"><span>Valor3</span>
<input type="radio" name="grupo1" value="Valor4"><span>Valor4</span>
<br><textarea name='arraytextArea[]'></textarea> <br>
<input type="radio" name="grupo2" value="Valor1"><span>Valor2</span>
<input type="radio" name="grupo2" value="Valor2"><span>Valor3</span>
<input type="radio" name="grupo2" value="Valor3"><span>Valor4</span>
<input type="radio" name="grupo2" value="Valor4"><span>Valor5</span><br>
<input type="button" value="Enviar" id="botao">
Javascript:
$(function () {
$("#botao").click(function () {
$("textarea[name='arraytextArea[]'],input[name='grupo1'],input[name='grupo2']" ).each(function (i,el) {
alert("Valor:"+$(el).val());
});
})})
You can also check out jsfiddle
I want to concatenate the spans of each radio group. As noted in the code we have the first group identified by teg name="group1", so I have to concatenate all the spans that are in that group and in all other groups. Saving each concatenation of each group in a vector index.
NOTE: The code has to serve to numerous groups and numerous radios.
EX:
vet[0]="valor1,valor2,valo3,valo4"; relativo ao name="grupo1"
vet[1]="Valor2,valor3,valor4,valor5"; relativo ao name="grupo2"