Skip to content

Instantly share code, notes, and snippets.

@mreidsma
Created November 6, 2014 17:08
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 mreidsma/b7dbab00b5b3f6119a5c to your computer and use it in GitHub Desktop.
Save mreidsma/b7dbab00b5b3f6119a5c to your computer and use it in GitHub Desktop.
Check for a keyword in III search, append if not in search query

Check query for search term, add on submit if not there

One of our librarians needed a way to limit searches to the catalog to atlases. However, the only good way to do that in our OPAC is by using the keyword "Atlas" with whatever other keywords you are searching. Since that's not always going to happen, I wrote a quick script that will check the search query for the keyword "atlas," and if it doesn't find it, will append it. This might be useful for other projects, as well.

<style>
form#querybox input { font-size: 1.1em; }
form#querybox input[type="text"] { border: 1px solid #bbb; padding: .2em 1%; width: 76%; }
form#querybox input[type="submit"] { background: #0090D2;border: 1px solid #4081af;border-bottom-color: #20559a;border-radius: 4px;box-shadow: inset 0 1px 0 rgba(255,255,255,.3), inset 0 0 2px rgba(255,255,255,.3), 0 1px 2px rgba(0,0,0,.29);color: white;display: inline-block;font-weight: normal;text-decoration: none;cursor: pointer;font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;padding: .2em 1%; width: 18%;}
</style>
<form action="http://library.catalog.gvsu.edu/search/" id="querybox" method="get" name="querybox" class="lib-book-form">
<input type="hidden" name="searchtype" value="X" />
<input name="SORT" type="hidden" value="D">
<input id="searcharg" name="searcharg" placeholder="Search for Atlases" type="text">
<input class="lib-button-small" type="submit" value="Search">
</form>
<script>
var searchForm = document.getElementById('querybox');
searchForm.addEventListener("submit", function(evt){
var searchTerms = searchForm.elements['searcharg'].value;
if(searchTerms.indexOf("atlas") == -1) { // patron did not use atlas keyword
searchTerms = searchTerms + ' atlas';
}
document.getElementById('searcharg').value = searchTerms;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment