Shortcode: Dropdown show div based on option

Hello

I'm trying to create a shortcode to show a dropdown (select) to display a certain div depending on the option selected. Example code which doesn't work:

function selectfilter_func() {

return "
<script>
$(document).ready(function(){
    $('#filter').on('change', function() {
      if ( this.value == '1')
      {
        $('#filter1').show();
      }
      else
      {
        $('#filter1').hide();
      }
    });
});
</script>

<select id='filter'>
<option value='0'>Filter 1</option>
<option value='1'>Filter 2</option>
<option value='2'>Filter 3</option>
</select>

<div style='display:none;' id='filter2'>
DISPLAY CONTENT FOR FILTER 2
</div>
";

}
add_shortcode( "selectfilter", "selectfilter_func" );

Any ideas why it's not working / how to fix?