I'm trying to find the selected value of a dropdown but I keep getting an empty string or undefined results.
My HTML looks like this:
<div class="input-group" style="padding-bottom: 10px;">
<span id="add-addon-styling" class="input-group-addon">Status</span>
<!-- TODO: Make this automatically rather than hardcoded -->
<select class="form-control required" id="new-activity-modal-status-dropdown">
<option value="NA" class="selected">N/A</option>
<option value="ON_TRACK">On Track</option>
<option value="ISSUE">Issue</option>
<option value="BEHIND">Behind</option>
</select>
<span class="input-group-addon" data-toggle="tooltip" data-placement="top" title="The Status of the Activity. Usually On Track but otherwise set to N/A if unsure.">
<b>?</b>
</span>
</div>
And here is the JavaScript:
function OnModalCreateNewActivityBtnClick() {
var jsonObject = '';
var modal = $('new-activity-modal-body');
var activityStatus = modal.find('#new-activity-modal-status-dropdown').val();
...
...
}
I've also seen this suggested:
function OnModalCreateNewActivityBtnClick() {
var jsonObject = '';
var modal = $('new-activity-modal-body');
var activityStatus = modal.find('#new-activity-modal-status-dropdown').find(":selected").text();
...
...
}
The first returns an undefined result. The second returns an empty string.
I'm not sure what to do. JavaScript still perplexes me.