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

163
Visualizações
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 Respostas
Responde à pergunta

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 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