How to get selected value from select box in angularjs


Sharmavikram

Hello everyone

I'm trying to get option value from select box on button click but it shows undefined in console. The option value comes from the server

Here is my HTML code

<div class="form-group">
        <label class="control-form" for="cityid">Selct City</label>
        <select type="text" class="form-control" placeholder="City" id="acity" >
            <option value="">--Select City--</option>
            <option ng-repeat="city in cityinfo" ng-value="{{city.id}}"  ng-selected="{{city.id ==cityid}}">{{city.cityname}}</option>
</select>

<button class="btn btn-info prevnext pull-right" ng-click="nextpage()">Next <i class="fa fa-arrow-right"></i></button>

Controller.js file code

  $scope.nextpage = function(pageno) {
   console.log($scope.cityinfo);
   }

selection box image

Thanks in advance

Roy

Use ng-optionsinstead ng-repeat.

like this:

renew

<select type="text" class="form-control" placeholder="City" id="acity" ng-options="city.id as city.cityname for city in cityinfo track by city.id" ng-model="selectedCity">
    <option value="">--Select City--</option>
</select>
<button class="btn btn-info prevnext pull-right" ng-click="nextpage(selectedCity)">Next <i class="fa fa-arrow-right"></i></button>

JS:

$scope.nextpage = function(selectedCity){
    console.log(selectedCity);
}

Related


How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

How to get the value of the selected option in a select box

giff if I want to show an alert with a checked option, but my form doesn't see the popup alert. Here is my PHP: <select class="form-control" id="status_users"> <option>All</option> <option>Active</option> <option>Inactive</option> <option>Try</option>

Get value from selected box in bs double column angularJS

monster java I am trying to get the selected value in a double box. Refer this link http://www.virtuosoft.eu/code/bootstrap-duallistbox/ I have done the following code snippet: .html <select name="duallistbox_demo1[]" ng-model="recSched

How to get selected value from textarea in angularjs

learner Hi, I'm working on an example of displaying values in a text area, here's a link to plunkr : http://plnkr.co/edit/QgWKTRsC6TBeqbFf80fO?p=preview <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/ang

How to get selected value from select component

Rafael Augusto How to get selected value from select component? select.component.ts: export class PfSelectComponent implements OnInit { constructor() { } ngOnInit() { } @Input() options : Array<Object>; } select.component.html <select [(ngModel)]=

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

How to get selected value from select component

Rafael Augusto How to get selected value from select component? select.component.ts: export class PfSelectComponent implements OnInit { constructor() { } ngOnInit() { } @Input() options : Array<Object>; } select.component.html <select [(ngModel)]=

How to get selected value from select component

Rafael Augusto How to get selected value from select component? select.component.ts: export class PfSelectComponent implements OnInit { constructor() { } ngOnInit() { } @Input() options : Array<Object>; } select.component.html <select [(ngModel)]=

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

How to get selected value from <select>

blow I try to get value from select area using form and $_Post. I've browsed through many older questions, and sure enough, I followed the directions. Still I get the error: Undefined array key 'platform'. <form action="" method="POST"> <select name="

How to get value from select box?

Nabil Imtiaz I want to get the value of the selected option from the selected box by using JQuery but it doesn't work. I've tried a million ways to do this. Try to get its text, try to get the value from multiple ways. To know what is in my jquery variable. $(

How to get value from select box?

Nabil Imtiaz I want to get the value of the selected option from the selected box by using JQuery but it doesn't work. I've tried a million ways to do this. Try to get its text, try to get the value from multiple ways. To know what is in my jquery variable. $(

How to get multiple selected values from select box in JSP?

Param-Ganak: I have an html form that has a select listbox from which you can select multiple values because its multiple property is set to multiple . Consider table methods as get methods. The html code of the form is as follows. <html> <head> <title>Untitle

How to get multiple selected values from select box in JSP?

Param-Ganak: I have an html form that has a select listbox from which you can select multiple values because its multiple property is set to multiple . Consider table methods as get methods. The html code of the form is as follows. <html> <head> <title>Untitle

How to get multiple selected values from select box in JSP?

Param-Ganak: I have an html form that has a select listbox from which you can select multiple values because its multiple property is set to multiple . Consider table methods as get methods. The html code of the form is as follows. <html> <head> <title>Untitle