I am generating an Html select in a form that is in a bootstrap 3 modal popup. I am trying to get the selected value and pass it through JQuery to dump to a database.
I have other input fields and a text area field using tinyMCE
that I get the value from without any issues at all using $('#id').val();
.
My select is super simple and displays in the view source as:
<select id='practitionerID' name='practitionerID' class='form-control'>
<option value="1">Doctor 1</option>
<option value="2">Doctor 2</option>
</select>
I am have tried many different ways to get the data to display and cannot for the life of me get the option value.
I have tried the following:
$('#practitionerID').prop('selectedIndex'); // give's me -1 no matter the option selected
$('#practitionerID').val(); // returns null
$('#practitionerID').text(); // returns null, dont want the text anyways
$("#practitionerID option:selected").val(); // returns undefined
$("#practitionerID option:selected" ).text(); //returns undefined, still not what i want.
EDIT: So it tried this and it actually gives me a value now but only ever gives me the first option in the dropdown even though i have chosen something else. $('#practitionerID :selected').val();
The only thing i can think of that is tripping this up is the fact that I am loading it in a modal? Maybe it cannot read into it for some reason to see the property?
When I load an existing record and get the data.event.practitionerID
it works gives me the value fine. However, I cannot seem to set the value when i get it though. So it appears to be an issue with the ID of this select but I just cant see where or how.
Any help would be greatly appreciated!