1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Dependent dropdown box using nya-bootstrap-select

Discussion in 'JavaScript' started by vinod_3466, Apr 6, 2017.

  1. #1
    I am using nya-bootstrap-select with AngularJs below is my scenario & sample data
    $scope.ports = [
    {
      "row_id": 1,
      "name": "Port1",
      "terminals": [
        {"row_id": 1, "name": "1A"},
        {"row_id": 2, "name": "1B"},
        {"row_id": 3, "name": "1C"}
      ]
    },
    {
      "row_id": 2,
      "name": "Port2",
      "terminals": [
        {"row_id": 4, "name": "2A"},
        {"row_id": 5, "name": "2B"},
        {"row_id": 6, "name": "2C"}
      ]
    } 
    Code (JavaScript):
    1. First dropdown should contain ports and second should contain terminals.
    2. Once i select a port in the first dropdown, only the terminals of the selected port should be shown in the second dropdown.
    3. If the model of each dropdown already has specific row_ids, the relevant option should be selected automatically.
    I could achieve the first two points and i am stuck with the third point. I used lots of workaround to achieve this. Please help me if there is a proven solution. I searched a lot over the internet a lot but no luck.
    SEMrush
     
    vinod_3466, Apr 6, 2017 IP
    SEMrush
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Write it as AJAX. Once the first dropdown is selected, send the server the choice and have the server decide whether the second dropdown should be selected or not, then send the client back the code for the dropdown (or have the client write the second dropdown based on the result of the first one if you can follow the code you write that way).
     
    Rukbat, Apr 9, 2017 IP