Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda