Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Pasar variables dinámicas con PHP ajax a Javascript

Así que quiero pasar una variable como: childage_error1 childage_error2 childage_error3 etc. Y tengo este código aquí:

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

Si coloco manualmente "gyermekkor_error1", funciona pero no funcionará en un bucle. Funciona en getElementById pero no al final.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

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

Estás sumando una cadena a un número más un número. Orden básico de operaciones de izquierda a derecha. El código no asume que usted quiso agregar i a 1 primero.

Así que estás consiguiendo

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

Necesitas rodear la parte de suma con paréntesis

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

O simplemente comience su bucle en uno para que no necesite el paso de adición.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!