I am trying to add a custom HTML block to the page with the below code.
I created a Drop-down List and a search button for redirecting pages.
But it seems like that window.location.href
doesn't work in WordPress.
Is there any way for adding the code to redirect the page?
<script>
searchButton.addEventListener('click', () => {
const selectedOption = filterSelect.value;
if (selectedOption === 'newsports') {
window.location.href = 'https://www.google.com/';
} else if (selectedOption === 'yahoo') {
window.location.href = 'https://www.yahoo.com/';
}
</script>
filterSelect.value
are you certain that's not empty? Can you add, immediately after theclick
listener,console.log( filerSelect.value );
and the check your console to see if there's actually anything there?