Skip to content

Instantly share code, notes, and snippets.

@greghunt
Created March 12, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghunt/10b36aa8c738f8aaa39e7d787f7d2b87 to your computer and use it in GitHub Desktop.
Save greghunt/10b36aa8c738f8aaa39e7d787f7d2b87 to your computer and use it in GitHub Desktop.
Auto-submit a form
$("[data-autosubmit]").on('change', function(){
$(this).parents("form").submit();
});
@greghunt
Copy link
Author

greghunt commented Mar 12, 2018

This is very useful for filters. Simply add this HTML:

<form>
  <select class="m-0" name="sort" data-autosubmit>
    <option value="-relevance">Sort by Relevance</option>
    <option value="date">Recent</option>
    <option value="title">Alphbetical</option>
  </select>
</form>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment