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

164
Vistas
Using the value from a property in a JS object as the value for form input

I am trying to input 18 scores for 18 different holes in a golf app, currently The input field name is dynamically updated and when you click the next or prev button the holeIndex is incremented by 1 or reduced by1.

On page load, I fill the scoreCardObj with the players current scores that are held in the database (If any exist, otherwise the input is blank) I want the value to match the value for the field in scoreCardObj so when I am inputting the score for Hole 4, the input name will be h4Score and I want the value to be that of scoreCardObj.h4Score but I need the 4 to be the value of the holeIndex+1 so something like scoreCardObj.h${holeIndex+1}Score SO far I can only get it to return the string "scoreCardObj.h1Score" if holeIndex is 0 then it changes to "scoreCardObj.h2Score" when I move to the next hole.

Below is the input value I want to have for the first hole and then it dynamically changes to h2Score when I move to the next hole.

 <div id='score-entry'>
  <h2 >Hole {holeIndex+1}</h2>
  <input name={`h${holeIndex+1}Score`} value={scoreCardObj.h1Score} onChange={onChangeScoreCard} type="number" min={"1"} max={"15"}></input>
  <p style={{color:"red"}}>Please enter gross scores</p>
 </div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I believe you can access the prop h1Score, h2Score, h3Score dynamically using the bracket notation:

scoreCardObj[`h${holeIndex+1}Score`]
about 4 years ago · Juan Pablo Isaza 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