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

103
Visualizações
Selected option returning tag not textual value

I have this bootstrap select element

   <select id="createAxiomSelect" class="form-select">
      <option selected vale="true">True</option>
       <option value="false">False</option>
    </select>

I am trying to get 'true' or 'false' when selected. Instead I am getting the tag "<option selected="" vale="true">True</option>"

I have tried many different ways to do this. eg:

  1. $("#createAxiomSelect").find("option:selected").text()
  2. $("createAxiomSelect").val()
  3. $("#createAxiomSelect option:selected").text()
  4. document.getElementById("createAxiomSelect").innerHTML

These all return "<option selected="" vale="true">True</option>"

Can someone please find where I am going wrong, thank you

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

0

Assuming you are using jQuery since it does state that in the question: Item #2 is close. The correct syntax would be:

$("#createAxiomSelect").val();

See first the jQuery id selector requires '#'. .val() will simply return the value of the selected option.

Note, you have a spelling error in your first option vale= rather than value=. This will return instead the text of the option thus 'True' rather than 'true'.

Otherwise, I think you are on the right track. You can also do this using straight JavaScript, but since you are using jQuery, I'd suggest staying with that pattern and not mix and match.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use document.forms['<formName>'].elements['<selectName>'].value.
Important: you should use name attribute, not id.

about 4 years ago · Juan Pablo Isaza Relatório

0

$("#createAxiomSelect option:checked").value
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