Angular JS: Pass a forms select option value to database not working

Dong Hoon Kim

I currently have a form with a <select> and options as below. I am trying to pass the values into my db, but when running the app category is coming out as undefined. The form is using ng-controller="eventCtrl"

Form Select Code Below.

<div class="input-field col s5">
 <select class="browser-default">
  <option value="" disabled selected>Choose your category</option>
  <option value="Mountain" ng-model="category">Mountain</option>
  <option value="Forest" ng-model="category">Forest</option>
  <option value="Beach & Sea" ng-model="category">Beach & Sea</option>
  <option value="Fresh Water" ng-model="category">Fresh Water</option>
  <option value="Aero" ng-model="category">Aero</option>
  <option value="Desert" ng-model="category">Desert</option>
 </select>
</div>

eventCtrl Code Below.

angular.module('socialApp')
 .controller('eventCtrl', function($scope, $http) {
  $scope.createEvent = function() {
   $http.post('/events/createEvent', {
    title: $scope.title,
    category: $scope.category,
    city: $scope.city,
    state: $scope.state,
    date: $scope.date,
    time: $scope.time,
    description: $scope.description
  })
  .then(function(result) {
    console.log(result.data.status);
    console.log(result);
  })
 };
});

I am so lost with this please help!

cnorthfield

The ng-model attribute should be on the select element instead of each option element as so:

<div class="input-field col s5">
 <select class="browser-default" ng-model="category">
  <option value="" disabled selected>Choose your category</option>
  <option value="Mountain">Mountain</option>
  <option value="Forest">Forest</option>
  <option value="Beach & Sea">Beach & Sea</option>
  <option value="Fresh Water">Fresh Water</option>
  <option value="Aero">Aero</option>
  <option value="Desert">Desert</option>
 </select>
</div>

I'd definitely look up the documentation on this as it's very detailed!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angular JS: Pass a forms select option value to database not working

From Dev

angular js select default value not working

From Dev

How to select dynamic select option value using angular js

From Dev

Angular JS - ng-click not working in select option [Chrome]

From Dev

Get the option value of the select tag on load in Angular JS

From Dev

Angular JS - display select option based on boolean value of dropdown

From Dev

Angular Select with an option value of space

From Dev

Angular.js pass value from select to another view

From Dev

how to pass select option value in angularjs

From Dev

angular bootstrap ui tabs select option not working

From Dev

angular bootstrap ui tabs select option not working

From Dev

Codeigniter in select option default value not working

From Dev

Automatically show database value after select an option

From Dev

vue.js v-bind:value is not working with select option form element

From Dev

Working with HTML select in Angular JS

From Dev

Show value of option when chosen on select in Angular

From Dev

Need help please with working with forms and angular js

From Dev

Empty Option field in Select tag - Angular js

From Dev

Empty Option field in Select tag - Angular js

From Dev

Not able to post the select option value in express js

From Dev

Select option in angular 2 not displaying proper value on selecting an option

From Dev

AngularJS select option dont pass value into http post request

From Dev

Pass select option value to input field using VueJS

From Dev

how pass value from select option to other select option in other form

From Dev

Angular Forms: On autocomplete select, define formcontrol value different to input value

From Dev

why display:none for "Select a option" in select in angular js?

From Dev

angular select ng-selected not working (with <option ng-repeat>)

From Dev

3 option select set value from database remove onchange

From Dev

How will i input a value on database depending on the Select Option of HTML

Related Related

  1. 1

    Angular JS: Pass a forms select option value to database not working

  2. 2

    angular js select default value not working

  3. 3

    How to select dynamic select option value using angular js

  4. 4

    Angular JS - ng-click not working in select option [Chrome]

  5. 5

    Get the option value of the select tag on load in Angular JS

  6. 6

    Angular JS - display select option based on boolean value of dropdown

  7. 7

    Angular Select with an option value of space

  8. 8

    Angular.js pass value from select to another view

  9. 9

    how to pass select option value in angularjs

  10. 10

    angular bootstrap ui tabs select option not working

  11. 11

    angular bootstrap ui tabs select option not working

  12. 12

    Codeigniter in select option default value not working

  13. 13

    Automatically show database value after select an option

  14. 14

    vue.js v-bind:value is not working with select option form element

  15. 15

    Working with HTML select in Angular JS

  16. 16

    Show value of option when chosen on select in Angular

  17. 17

    Need help please with working with forms and angular js

  18. 18

    Empty Option field in Select tag - Angular js

  19. 19

    Empty Option field in Select tag - Angular js

  20. 20

    Not able to post the select option value in express js

  21. 21

    Select option in angular 2 not displaying proper value on selecting an option

  22. 22

    AngularJS select option dont pass value into http post request

  23. 23

    Pass select option value to input field using VueJS

  24. 24

    how pass value from select option to other select option in other form

  25. 25

    Angular Forms: On autocomplete select, define formcontrol value different to input value

  26. 26

    why display:none for "Select a option" in select in angular js?

  27. 27

    angular select ng-selected not working (with <option ng-repeat>)

  28. 28

    3 option select set value from database remove onchange

  29. 29

    How will i input a value on database depending on the Select Option of HTML

HotTag

Archive