Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Pass dynamic variables with PHP ajax to Javascript

So I want to pass a variable like : childage_error1 childage_error2 childage_error3 etc. And I have this code right here:

for (var i = 0; i < gyermekek; i++) {
      document.getElementById('gyermekkor_error' + (i + 1) + '').innerHTML = response.window['gyermekkor_error'+i+1]
    }

If I put manually "gyermekkor_error1" it works but it wont work in a loop. It works in getElementById but not in the end.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

response.window['gyermekkor_error'+i+1]

You are adding a string to a number plus a number. Basic order of operations left to right. The code does not assume you meant to add i to 1 first.

So you are getting

'gyermekkor_error01'
'gyermekkor_error11'
'gyermekkor_error21'
'gyermekkor_error31'

You need to surround the addition part with parenthesis

response.window['gyermekkor_error' + (i+1)]

Or just start your loop off at one so you do not need the addition step.

for (var i = 1; i <= gyermekek; i++) {
  var key = 'gyermekkor_error' + i;
  document.getElementById(key).innerHTML = response.window[key];
}
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda