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);
});