Lakshmi Narasimhan Lakshmi Narasimhan - 29 days ago 9
AngularJS Question

Is there a way to get the value of {{org}} from this?

<html>
<input type="text" ng-model="selectedOrg" ng-show="!isSuperAdmin" readonly />
<select id="nameOrg" ng-model="selectedOrg" ng-change="changeOrg()" ng-disabled="!isSuperAdmin" ng-show="isSuperAdmin">
<option ng-repeat="org in orglist">{{org}}</option>
</select>
<script>
var value = $(nameOrg).val()
</script>
</html>

Answer

Without the quotes, nameOrg is an invalid JavaScript variable.

    $(nameOrg)

Here's the right way to select an element by it's ID:

    $('#nameOrg')

Reference: https://api.jquery.com/id-selector/

Also, I see your html document does not contain any reference of jQuery. Make sure you are importing the library.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

I strongly suggest wrapping the code in a jQuery ready function as well, otherwise $ will not be available at runtime.

After you have done all the above, refer to the linked duplicate question on how to get the selected text. What .val() does is to get the selected option's value (<option value="text"></option>), not the text between the option tag (<option>text</option>).