Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

laravel data showing in single option instead of multiple option from json array

//Your data structure is fine. The issue is that you're not creating multiple option elements, you're only creating one. This part is off:

$("#cityPicker").append('<option value="' + value
                            .districts + '">' + value.districts + '</option>');
                        }
//what you want to do is create an option element for each district, as follows:

for (const district of value.districts) {
  $("#cityPicker").append('<option value="' + district + '">' + district + '</option>');
}
 
PREVIOUS NEXT
Tagged: #laravel #data #showing #single #option #multiple #option #json #array
ADD COMMENT
Topic
Name
1+6 =