landbryo
3/23/2018 - 6:19 PM

Add Hash to URL based on selected option

Adds hashtag to URL based on selected option.



<script>
var url = window.location.href;
if (url.search("country=") >= 0) {
	window.location.hash = "#locator";
}
</script>

<a name="locator"></a>
<form>
	<select name="country" id="country-menu">
		<option value="">FILTER BY COUNTRY</option>
		<?php foreach($countries as $key => $label) : ?>
			<option value="<?=$key?>" id="<?=$key?>"<?php if ($key== $country) : ?> selected<?php endif; ?>><?=$label?></option>
		<?php endforeach?>
	</select>
	<input type="submit" style="display:none;">
</form>