Andrew Vanusi Andrew Vanusi - 1 year ago 69
jQuery Question

Append an array values into select option Jquery

Im currently using Laravel

here's my jquery code so far :

$('button[type="search"]').click(function(e) {
url: "{{ route('car.plate_no') }}",
type: "POST",
data: {
'_token' : '{{csrf_token() }}',
'driver_id' : $('select[name="driver_id"]').val(),
'fine_date' : $('input[name="fine_date"]').val(),
success: function(data) {
if(data.status == true) {
var result = '';

$.each(data.getCarbyDriver, function(i, data) {
result += '<div>'+ data.plate_no +'</div>';
error: function(data) {


and here's my form code so far :

<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group filter-btn">
<button class='btn btn-info' type='search'>Search</button>

<select id="search-result"></select>

everything works fine, data is being returned.

how do i append plate_no data into select box and store it to database .

any idea ?

Answer Source

Javascript: inside foreach:

result += '<option value='+data.plate_no+'>'+data.plate_no+'</option>';


<select name="" id="search-result">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download