laravel PHP空格字符中的下拉列表不起作用

i have two dropdowns, and when I click on item inside the first one, the second one is automaticaly updated, i am doing this with JQuery. It's working fine, but only if there is not space characters inside the Item from the first list, so for example if I have "Some item" as item, it will do nothing, but for "item" it will update another list. Here is the Jquery code, and Laravel PHP code. Can you please tell me why it's making problem with spaces inside first dropdown?

  <select name="podrucje" id="select1" style='width: 150px;'>                     
          @foreach( $projects_all as $project )
           <? if ($project->name != null)  { ?>

      <option value="{{ $project->podrucje }}">{{ $project->name}}</option>

               <? }  ?>
      @endforeach
      </select>

This is Jquery Script for on item change for the first list:

     $("#select1").change(function () {
    if ($(this).data('options') == undefined) {
        /*Taking an array of all options-2 and kind of embedding it on the select1*/
        $(this).data('options', $('#select2 option').clone());
    }
    var id = $(this).val();
    var options = $(this).data('options').filter('[value=' + id + ']');
    $('#select2').html(options);



    });

seems to work if you put double quotes around the value in your filter.

so line 7 of your js would become

var options = $(this).data('options').filter('[value="' + id + '"]');

see this for working example (last value in dropdown had space in value)

https://jsfiddle.net/5mb7oot4/1/

You'd need to encapsulate the filter value in quotes.

var options = $(this).data('options').filter('[value="' + id + '"]');