Skip to content

Instantly share code, notes, and snippets.

@rdallaire
Last active December 20, 2015 17:09
Show Gist options
  • Select an option

  • Save rdallaire/6166989 to your computer and use it in GitHub Desktop.

Select an option

Save rdallaire/6166989 to your computer and use it in GitHub Desktop.
Search Drop Down for Stores/ blogs
searchHandler: function() {
var searchForm = $('#search-form'), // ID on the form tag
searchInput = $('#search-input'), // ID on the search input box
searchOptions = $('#search-options'); // ID on the html select tag
// Set the default to the store
searchForm.attr('action', 'http://supergamesinc.dev.crystalcommerce.com/products/search');
searchInput.attr('name', 'q');
searchOptions.on('change', function() {
var selectValue = searchOptions.val();
if(selectValue === "store") {
searchForm.attr('action', 'http://supergamesinc.dev.crystalcommerce.com/products/search');
searchInput.attr('name', 'q');
} else if(selectValue === "articles") {
searchForm.attr('action', 'http://supergamesinc.wpengine.com/index.php');
searchInput.attr('name', 's');
} else if(selectValue === "buylist") {
searchForm.attr('action', 'http://supergamesinc.dev.crystalcommerce.com/buylist/search');
searchInput.attr('name', 'q');
}
if(searchInput.val() !== '') {
searchForm.submit();
}
});
}
<!-- HTML -->
<form name="search-form" id="search-form" method="GET" action="http://supergamesinc.dev.crystalcommerce.com/products/search">
<input type="text" id="search-input" name="q" placeholder="Search...">
<select id="search-options">
<option value="store" selected="selected">Store</option>
<option value="articles">Articles</option>
<option value="buylist">Buylist</option>
</select>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment