Hi, this is my first post here so I’m not really sure how to format this. I’ve recently completed the survey form project, however, I was wondering if it was possible to have the submit button redirect to another page after completion? I’ve tried using anchor tags but that hasn’t been working so far. Any help would be appreciated.
Run a function to open a new tab when user presses submit button.
//define the urls
const urls = {
success: "https://google.com"; //when the form is valid,
tryAgain:"https://freecodecamp.com" //when form is not valid
}
const form = document.getElementById('survey-form'); //grab the HTML-element
const executeWhenUserSubmitsForm = function (e){
e.preventDefault(); //read about preventDefault()
form.checkValidity()? window.open(urls.success):
window.open(urls.tryAgain);
}
form.addEventListener('submit', (e)=>executeWhenUserSubmitsForm)