0

I am using ajax to pull data from a database and returning it in json format and want to create a drop down filter.

  $.ajax({
    url: `url`,
    dataType: 'json',
    success: function (results) {
      $.each(results, function (index, value) {
       console.log(value.name)
)}

I want to create a select menu where all the names in value.names are there, and when the user selects I want to do

 let userInput = $("select").val();

and then only show the results where the ajax value.name matches the user input?

Is this possible?

jfc
  • 361
  • 3
  • 15

1 Answers1

0
    **<input type="text" id="Name"/>**
-------------------------------------------------------------------------------
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" 
   type="text/javascript"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
----------------------------------------------------------------------------
   <script >
 $(document).ready(function () {
        $("#Name").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "Url",
                    type: "POST",
                    dataType: "json",
                    data: { Data: request.Name},
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.Name, value: item.Name};
                        }))
    
                    }
                })
            },
            messages: {
                noResults: "", results: ""
            }
        })
</script>
Divyanshi Mishra
  • 110
  • 1
  • 11