1

I´m trying to get the value from a dropdown when submitting a form in AngularJS but ends up with an undefined value. See this fiddle: http://jsfiddle.net/ironhead/Td2NZ/280/ textfields works with $scope.nameoftextbox but how to get the name/value of a dropdown?

<form ng-submit="submitForm()" novalidate>
    <select name="test" ng-model="form.type" ng-options="option.name for option in typeOptions" ></select>
    <input type="submit" value="submit">
</form>

<script>
    $scope.submitForm = function (post) {
    alert($scope.test);
}
</script>
1
  • 1
    Your model is form.type so $scope.form.type Commented Nov 24, 2014 at 23:06

1 Answer 1

1

With ng-model directive, you bind a specific $scope property - form.type - to that select. This model's value changes when a user selects different options, according to how these elements were created in the first place (with ng-options directive). So you only have to check the model's value, that's all! For example:

alert($scope.form.type.name);

Demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.