{
document.addEventListener("submit", (ev) => {
const form = ev.target;
const value = form.subject.value;
// Return if doesn't contain class
if (!form.classList.contains("my-class-name")) {
return;
}
// Prevent Default
ev.preventDefault();
// Return if no value
if (!value || value === "0" || value === "") {
return;
}
// Redirect to search page
window.location = value;
});
}
Created
November 4, 2019 20:54
-
-
Save germanny/ef6d04978318b0566369bf947b2721fb to your computer and use it in GitHub Desktop.
JavaScript - Redirect to <option> value on form submission
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment