Pre-select the dropdown select option according to value received

TArora23

I have a table of bookings in which the last field is of status with dropdown as

<td><select id="selectID" ng-selected="{{data.status}}">
                               <option value="1">New</option>
                               <option value="2">To Be Approved</option>
                               <option value="3">Cancelled</option>
                               <option value="4">Rejected</option>
                               <option value="5">Approved</option>
                               <option value="6">On The Way</option>
                               <option value="7">Delivered</option>
                               <option value="8">Ongoing</option>
                               <option value="9">Checkedout</option>
                               <option value="10">Completed</option>
                               <option value="11">Invoice Pending</option>
                               <option value="12">Invoice Sent/Payment Pending</option>
                               <option value="13">Green</option>

                           </select> </td>

I receive the value of status in the JSON as a number between 1-12. I want to pre-select every drop-down when i load my table . eg If JSON has status as 2 , then default selected in the row with status must be "To be approved" and so on . I have looked a lot , but all i could find was ng-options which is used to populate the select tag , but i don't receive them in the JSON so i have hard coded it in the <td> tags where each row is working on ng-repeat. Also , I thought of using .val function but i guess for different rows i might have to set different ids.

michelem

Just use AngularJS data binding with ng-model

JSFiddle

HTML:

<div ng-app="myApp" ng-controller="dummy">{{data.status}}
    <td>
        <select id="selectID" ng-model="data.status">
            <option value="1">New</option>
            <option value="2">To Be Approved</option>
            <option value="3">Cancelled</option>
            <option value="4">Rejected</option>
            <option value="5">Approved</option>
            <option value="6">On The Way</option>
            <option value="7">Delivered</option>
            <option value="8">Ongoing</option>
            <option value="9">Checkedout</option>
            <option value="10">Completed</option>
            <option value="11">Invoice Pending</option>
            <option value="12">Invoice Sent/Payment Pending</option>
            <option value="13">Green</option>
        </select>
    </td>
</div>

JS:

angular.module('myApp', [])
    .controller('dummy', ['$scope', function ($scope) {

    $scope.data = {
        status: 2
    };
}]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

create a select dropdown option with values and text according to the specified data attribute

From Dev

Select dropdown option by value using jQuery

From Dev

Select Dropdown option based on its text not value

From Dev

Javascript to select option in dropdown list with VALUE

From Dev

Change the existing value in a select/option dropdown with JQuery

From Dev

How to get the option value of selected in Select dropdown

From Dev

Select dropdown option by value using jQuery

From Dev

Select an option without changing the dropdown's value

From Dev

How to style the "option" value in select dropdown?

From Dev

select dropdown value according to previous valuesubmit new one

From Dev

pre-select value in dropdown list from mysql data

From Dev

Show different select according to the selected option of a select

From Dev

python selenium select dropdown option with value matching regex

From Dev

AngularJS + Protractor How to select Dropdown option based on its text not value

From Dev

Dropdown Menu: onChange, find select id of option value

From Dev

Get the string, but not the value from dropdown list option select

From Dev

Select dropdown option value not getting affected until it changes

From Dev

Insert a "Select Value" option in dropdown list from array using jQuery

From Dev

Disable option values in one select dropdown depending on value selected in another

From Dev

Get the string, but not the value from dropdown list option select

From Dev

How to create an option in a select dropdown that has no value in PHP

From Dev

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

From Dev

Angular different option value or string given an expression in select dropdown

From Dev

angularjs 1.7 select dropdown is showing an extra option value

From Dev

Show div on select dropdown option

From Dev

Select option of choice dropdown in a form

From Dev

dropdown option select in register form

From Dev

Select DropDown option using selenium

From Dev

Select a dropdown option using javascript

Related Related

  1. 1

    create a select dropdown option with values and text according to the specified data attribute

  2. 2

    Select dropdown option by value using jQuery

  3. 3

    Select Dropdown option based on its text not value

  4. 4

    Javascript to select option in dropdown list with VALUE

  5. 5

    Change the existing value in a select/option dropdown with JQuery

  6. 6

    How to get the option value of selected in Select dropdown

  7. 7

    Select dropdown option by value using jQuery

  8. 8

    Select an option without changing the dropdown's value

  9. 9

    How to style the "option" value in select dropdown?

  10. 10

    select dropdown value according to previous valuesubmit new one

  11. 11

    pre-select value in dropdown list from mysql data

  12. 12

    Show different select according to the selected option of a select

  13. 13

    python selenium select dropdown option with value matching regex

  14. 14

    AngularJS + Protractor How to select Dropdown option based on its text not value

  15. 15

    Dropdown Menu: onChange, find select id of option value

  16. 16

    Get the string, but not the value from dropdown list option select

  17. 17

    Select dropdown option value not getting affected until it changes

  18. 18

    Insert a "Select Value" option in dropdown list from array using jQuery

  19. 19

    Disable option values in one select dropdown depending on value selected in another

  20. 20

    Get the string, but not the value from dropdown list option select

  21. 21

    How to create an option in a select dropdown that has no value in PHP

  22. 22

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

  23. 23

    Angular different option value or string given an expression in select dropdown

  24. 24

    angularjs 1.7 select dropdown is showing an extra option value

  25. 25

    Show div on select dropdown option

  26. 26

    Select option of choice dropdown in a form

  27. 27

    dropdown option select in register form

  28. 28

    Select DropDown option using selenium

  29. 29

    Select a dropdown option using javascript

HotTag

Archive