Created
January 28, 2021 21:30
-
-
Save MattMcAdams/cd1574a51281e37897e3789c617be3ec to your computer and use it in GitHub Desktop.
Redirect based on form selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="myForm"> | |
<select id="select"> | |
<option value="pageSlug1">Page Title 1</option> | |
<option value="pageSlug2">Page Title 2</option> | |
<option value="pageSlug3">Page Title 3</option> | |
</select> | |
<button onclick="selectRedirect()">Submit</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prevent submit button from refreshing page | |
document.getElementById("myForm").addEventListener('submit', handleForm); | |
function handleForm(event) { event.preventDefault(); } | |
function countyRedirect() { | |
let field = document.getElementById("select"); | |
let value = field.value; | |
console.log(field, value); | |
window.location.href = "https://example.com/" + value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment