I have a dropdown menu that I want people to click and redirect to another page.
This is my HTML code:
<!DOCTYPE html>
<html>
<select id="searchengine" name="searchengine" class="searchengineSelector">
<option value="">Select an option</option>
<option value="GO">Google</option>
<option value="YA">Yahoo</option>
</select>
<div>
<button class="searchSelect" id="search_button">Explore</button>
</div>
</html>
<script>
const links = {
GO: 'https://www.google.com',
YA: 'https://www.yahoo.com',
}
document.getElementById('search_button').addEventListener('click', () =>
location.href = links[document.getElementById('searchengine').value])
</script>
Using this script everything works but I want it to open in a new tab. How can I do that? I tried adding a '_blank' next to the link but it doesn't work.
Thank you!