As per Javascript variable within an html value?

1

I have the following code:

console.log(ArmazenaIds);
console.log(ArmazenaEmails);
contaQuantidadeDeEmails = ArmazenaEmails.length;
//listando emails selecionados na div .top 
for( c=0; c<contaQuantidadeDeEmails; c++) {

  $('ul').append('<li>'+ArmazenaEmails[c]+'</li>');
  // COLOCANDO CADA EMAIL DENTRO DO VALUE PRA ENVIAR PELO FORM
  //USANDO AJAX
  $('#novo').append("<input type='hidden' name='emailzinhos[]' value='aff' /> ");
}

How do I put the ArmazenaEmails[c] vector inside value='aff' , I do not know how to do this, I tried with + and it's giving me a syntax error, it's a simple question I just do not know the answer.

    
asked by anonymous 19.11.2017 / 19:50

2 answers

0

By selecting the tag input with the value "aff" .

Just add the following statement:

$('input[value="aff"]').val(ArmazenaEmails[c]);

Looking like this:

console.log(ArmazenaIds);
console.log(ArmazenaEmails);
contaQuantidadeDeEmails = ArmazenaEmails.length;
//listando emails selecionados na div .top 
for( c=0; c<contaQuantidadeDeEmails; c++) {

  $('ul').append('<li>'+ArmazenaEmails[c]+'</li>');
  // COLOCANDO CADA EMAIL DENTRO DO VALUE PRA ENVIAR PELO FORM
  //USANDO AJAX
  $('#novo').append("<input type='hidden' name='emailzinhos[]' value='aff' /> ");
  $('input[value="aff"]').val(ArmazenaEmails[c]);
}
    
19.11.2017 / 19:57
3

You can concatenate the values of the ArmazenaEmails[c] vector in the string:

for( c=0; c<contaQuantidadeDeEmails; c++) {
  $('ul').append('<li>'+ArmazenaEmails[c]+'</li>');
  // COLOCANDO CADA EMAIL DENTRO DO VALUE PRA ENVIAR PELO FORM
  //USANDO AJAX
  $('#novo').append("<input type='hidden' name='emailzinhos[]' value='"+ArmazenaEmails[c]+"' /> ");
}

In this example, I'm going to remove hidden from inputs to see the value:

ArmazenaEmails = ['[email protected]','[email protected]','[email protected]'];

contaQuantidadeDeEmails = ArmazenaEmails.length;
//listando emails selecionados na div .top 
for( c=0; c<contaQuantidadeDeEmails; c++) {
  $('ul').append('<li>'+ArmazenaEmails[c]+'</li>');
  // COLOCANDO CADA EMAIL DENTRO DO VALUE PRA ENVIAR PELO FORM
  //USANDO AJAX
  $('#novo').append("<input type='' name='emailzinhos[]' value='"+ArmazenaEmails[c]+"' /> ");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="novo">
   <ul>
   </ul>
</div>
    
19.11.2017 / 20:39