Skip to content

Instantly share code, notes, and snippets.

@evercode1
Last active January 16, 2017 20:22
Show Gist options
  • Save evercode1/5e0fb922e7bf0926c97e to your computer and use it in GitHub Desktop.
Save evercode1/5e0fb922e7bf0926c97e to your computer and use it in GitHub Desktop.
jquery for dropdown
@section('scripts')
<script>
$('#category_id').on('change', function(e){
var cat_id = e.target.value;
//ajax
$.get('/api/category-dropdown?cat+id=' + cat_id, function(data){
//success data
$('#subcategory_id').empty();
$('#subcategory_id').append('<option value=""> Please choose one</option>');
$.each(data, function(index, subcatObj){
$('#subcategory_id').append('<option value="' + subcatObj.id+'">'
+ subcatObj.subcategory_name + '</option>');
});
});
});
</script>
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment