Lets say I have a drop-down list defined like this:
HTML
<select class="form-control" id="groupId">
<option value="1">Administrator</option>
<option value="2">Member</option>
<option value="3">Guest</option>
<option value="4">Traveller</option>
</select>
Which looks like:
If I do a naive thing such as...
JavaScript
console.log(
$('select#groupId').text()
);
...the output is a very confusing jumble of all your option text values...
JavaScript
AdministratorMemberGuestTraveller
Instead you have to use the :selected selector on the drop-down list option value like so...
JavaScript
console.log
$('select#groupId option:selected').text()
);
This produces the correct output that is a single text value for the currently selection option.
-i