Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery dropdown options in laravel

@section('scripts')
    <script type="text/javascript">
        $("#country").change(function(){
            $.ajax({
                url: "{{ route('admin.cities.get_by_country') }}?country_id=" + $(this).val(),
                method: 'GET',
                success: function(data) {
                    $('#city').html(data.html);
                }
            });
        });
    </script>
@endsection
Comment

jquery dropdown options in laravel

public function get_by_country(Request $request)
{
    abort_unless(Gate::allows('city_access'), 401);

    if (!$request->country_id) {
        $html = '<option value="">'.trans('global.pleaseSelect').'</option>';
    } else {
        $html = '';
        $cities = City::where('country_id', $request->country_id)->get();
        foreach ($cities as $city) {
            $html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
        }
    }

    return response()->json(['html' => $html]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get the total price of all product in cart using react 
Javascript :: save specific attributes in table: sequelize 
Javascript :: code mirror detect change 
Javascript :: js dom after selectors 
Javascript :: Private slots are new and can be created via Private methods and accessors 
Javascript :: strapi extend user model 
Javascript :: how we pass 2 args in switch case javascript 
Javascript :: upload image in react next js authentication 
Javascript :: javascript keyup original src element 
Javascript :: automatice color change 
Javascript :: javascript returns odd 
Javascript :: last iteration is for loop js ES6 
Javascript :: serverless web app with react netlify 
Javascript :: showing error for few seconds react 
Javascript :: JavaScript URL Parse Seperate Parsing 
Javascript :: Adding Notices in the Block Editor Wordpress 
Javascript :: copy file using java script 
Javascript :: Imports should be sorted alphabetically sort-imports 
Javascript :: expo google sign inredirect uri mismatch 
Javascript :: nodejs express mongodb boilerplate 
Javascript :: keep form values after submit javascript 
Javascript :: encrypt and decrypt in js 
Javascript :: js Set get elements by array 
Javascript :: peopleToSendMessage 
Javascript :: react 5 to 10 rating 
Javascript :: slide div on click angular 
Javascript :: sequelize default curdate 
Javascript :: fabic js save and render 
Javascript :: error code ELIFECYCLE REACTJs 
Javascript :: Cannot find module Cannot find module 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =