BKM
BKM

Reputation: 186

how to select the value of a select dropdown using javascript/angularJS

this is how i am trying to access the select dropdown and now i want to select the option of which i have a value :

var A    
A= document.getElementById("aID");

this is the value i am getting while editing a row record using angular JS :

$scope.Act[index].ATextValue;

and i am trying to get which is wrong but i want the correct solution or way to do this :

 document.getElementById("aID").selectedValue=$scope.Act[index].ATextValue;

Upvotes: 0

Views: 101

Answers (2)

Mustafa Kunwa
Mustafa Kunwa

Reputation: 867

Try Using this code

<select ng-model="selectedName" >
   <option ng-repeat="x in names" ng-value="x">{{x}}</option>
</select>

Upvotes: 1

JP Dolocanog
JP Dolocanog

Reputation: 451

I'm not sure what you are trying to achieve but here is a sample snippet on implementing a simple dropdown select.

HTML for Dropdown:

<select ng-model="selectedName" ng-change="ShowSelectedValue()"
        ng-options="x for x in names">

Angularjs:

// Dropdown Items
$scope.names = ["a", "b", "c"];

// When an item is selected, an alert is displayed
// $scope.selectedName will be the container of the selected value
$scope.ShowSelectedValue = function (){
  alert($scope.selectedName);
}

I hope this helps!

Upvotes: 1

Related Questions