Jump to content
Fórum Script Brasil
  • 0

não consigo selecionar o valeu de uma select


Question

Estou tentando pegar o valor do value de um option que estou criando dinamicamente, os dados vem de uma api, ele carrega o option no select, tudo certo, mas quando eu busco o ivalue do option, não vem o value e sim o text. 


const criaOption=(horario, id)=>{
    const novaOptionTurma=crE('option')
    const option=
        `
        <option value="${id}">${horario}</option>
        `
    novaOptionTurma.innerHTML=option
    return novaOptionTurma
}
const select=$('[data-turma]')
listaTurmas()
.then(data=>{
    data.forEach(elemento=>{
        select.appendChild(criaOption(elemento.horario,elemento.id))
    })
})

const btnPegaTurma=$('.btn_turma')
btnPegaTurma.addEventListener('click',(evento)=>{
    evento.preventDefault()
    const turma=$('[data-turma]').value
    console.log(turma)
    localStorage.setItem('truma', turma)
})
 
Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149279
    • Total Posts
      645643
×
×
  • Create New...