Skip to main content
King County logo

If you want to offer your users the opportunity to search within only a certain site or section of a site, use this code snippet. The example below would search Solid Waste's media library.

  • Edit "Search within this section" to say whatever you want the button to say.
  • Edit "https://kingcounty.gov/~media/services/environment/dnrp/ecoconsumer/" to be whatever area you want to limit the search to. 

Step one: Put this in your HTML code where you want the search form to appear.

<form id="search_form" action="//www.kingcounty.gov/search" method="get" accept-charset="UTF-8">

<div style="margin: 0px; padding: 0px; display: inline;">

<input name="utf8" type="hidden" value="✓" />

</div>

<label for="query">Enter term(s): </label>

<input name="q" id="query" type="text" />

<input name="commit" type="submit" value="Search within this section" onclick="searchSpecial()" />

</form>

Step two: Put this in the custom script field:

<script>

function searchSpecial()

{

var specialsearch = $( "#query" );

specialsearch.val( "site:https://kingcounty.gov/~media/services/environment/dnrp/ecoconsumer/" + specialsearch.val() );

}

</script>