0

I m trying to get a dynamic dropdown menu using another dropdown. here this is my blade file.

<div class="form-group">
{!! Form::label('ItemID', 'Code:') !!}
<select class="form-control input-sm" name="ItemID" id="ItemID">
@foreach($items as $itm)
<option value="{{$itm->ID}}">{{$itm->Code}}</option>
@endforeach  
</select>
</div>


<div class="form-group">
{!! Form::label('ActivityItemsID', 'Activity:') !!}
<select class="form-control input-sm" name="ActivityItemsID" id="ActivityItems">
<option value=""></option>

</select>
</div>

my first dropdown works fine.
This is my route.php

Route::get('/addschedule',function(){
$itemID = Input::get('ItemID');
$sub = DB::table('ActivityItem')->where('ItemID','=',$itemID)->get();
return $sub;
});


This is the script I used.

<script>

   $.ajaxSetup({
   headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   }

$('#ItemID').on('change', function(e){
    console.log(e);
    var itemID = e.target.value;

    $.get('{{ url('information') }}/addschedule?itemID=' + itemID, function(data) {
        console.log(data);
        $('#ActivityItems').empty();
        $.each(data, function(index,subCatObj){
            $('#ActivityItems').append(''+subCatObj.name+'');
        });
    });
});

});
</script>

When I try this, I get

Uncaught SyntaxError: Unexpected identifier

What is the problem with my code? I am using Laravel 5.2 and Mysql.
Thanks in advance.

2
  • please share your table structure Commented Jul 26, 2016 at 19:10
  • 1
    Most likely you forgot to end a section. Inspect your html and you will find the issue Commented Jul 26, 2016 at 21:07

1 Answer 1

1

You have an error in your JavaScript. You haven't closed the function call to $.ajaxSetup() correctly. Your code should look more like this:

<script>

$.ajaxSetup({
   headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   }
});

$('#ItemID').on('change', function(e) {
     console.log(e);
     var itemID = e.target.value;

     $.get('{{ url('information') }}/addschedule?itemID=' + itemID, function(data) {
        console.log(data);
        $('#ActivityItems').empty();
        $.each(data, function(index,subCatObj){
            $('#ActivityItems').append(''+subCatObj.name+'');
        });
     });
});

Sign up to request clarification or add additional context in comments.

1 Comment

Still get the same error. Uncaught ReferenceError: $ is not defined near $.ajaxSetup({

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.