Search code examples
javascriptasp.netamadeus

JavaScript Attribute Value From DropDownList Selection


I have a DropDownList with Text Field and Value Field populated from SQL Server database. I wish to get Value Field selected by the user and input into the "country: " which below "term: request term" in the JavaScript. Thanks for every members here that help.

DropDownList:

<asp:DropDownList ID="CountryDDL" runat="server" Height="100%"></asp:DropDownList>

JavaScript:

<script>
    $(function () {
        $("[id$=OriginLocationTextBox]").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "https://api.sandbox.amadeus.com/v1.2/airports/autocomplete",
                    dataType: "json",
                    data: {
                        apikey: "API KEY",
                        term: request.term,
                        country: 
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            },
            minLength: 3,
        });
    });
</script>

Solution

  • If you dun need to collect the data through .net but ajax, you can just do this:

    DropDownList:

    <asp:DropDownList ID="CountryDDL" runat="server" Height="100%" onchange="requestfunc(this.options[this.selectedIndex].value)"></asp:DropDownList>
    

    JavaScript:

    <script>
        function requestfunc(val){
        $(function () {
            $("[id$=OriginLocationTextBox]").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "https://api.sandbox.amadeus.com/v1.2/airports/autocomplete",
                        dataType: "json",
                        data: {
                            apikey: "API KEY",
                            term: request.term,
                            country: val
                        },
                        success: function (data) {
                            response(data);
                        }
                    });
                },
                minLength: 3,
            });
        });
        }
    </script>