• Resolved Elliot Sowersby

    (@elliotvs)


    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?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode: Dropdown show div based on option’ is closed to new replies.