I created a list of options using html and placed a button beneath it...I want the user to select an option and when he clicks on the button,it redirects him to a different page... Is there anyway that I can do this using JavaScript please?
CodePudding user response:
Yes, window.location.href = "/someLocation"
just is made for you.
CodePudding user response:
when you click in the button you can call a function and inside of this function you put
window.location.href = "your-url"
or you can use window.open("your-url")
to open a new tab.
<select onChange="goToPage(value)">
<option disabled selected value> -- select an option -- </option>
<option value="https://google.com" > google </option>
<option value="https://stackoverflow.com" > stackOverflw </option>
<option value="https://github.com" > git </option>
</select>
<script>
function goToPage(value) {
window.location.href = value
}
</script>
you an see more in this link here