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

98
Visualizações
How to get ID of a member from a dropdown box

I am trying to get the best way to get a member's ID so I can send it with an api request, currently I have a drop down menu which shows all the current members.

 <select name="member_id" id="member_id" className={`form-control ${memberSelected ? "is-valid" : "is-invalid"} `}  label="Member" placeholder="select" onChange={onChangeMember} required>
     <option selected disabled value="">Please select</option>
           {members[0].id && members.map((member) => {
              return ( <option key={member.id}> {member.id} {member.firstName} {member.surname} </option>
           );
       })};
 </select>

The only way I have so far found to be able to get the ID so I can send it to the api, is to put the member id on the dropdown, get its value and then use a split method to just get the id,

membersId.split(" ")[0] This works fine, but I dont really want to have the id number showing on the dropdown.

So I want to just show the name Joe bloggs and if they are selected on the dropdown, then this updates membersId with Joe Bloggs ID number.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

<option key={member.id} value={member.id}> {member.firstName, + ' ' + member.surname} </option>

Then you can use onChange event or document.getElementById("idName") for catching the selected member id's

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this..

const handleOnChangeMember = (event) => {
   const memberId = event.target.value;
    // Do api call with member id
}

<select ... onChange={handleOnChangeMember} required>
   <option selected disabled value="">Please select</option>
   {
      members && members.map((member) =>
          <option value={member.id}>{member.firstName} {member.surname} </option>
   }
</select>
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