Home > Mobile >  Selected option returning tag not textual value
Selected option returning tag not textual value

Time:04-26

I have this bootstrap select element

   <select id="createAxiomSelect" >
      <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

CodePudding user response:

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

CodePudding user response:

$("#createAxiomSelect option:checked").value
  • Related