I want to have the page redirect after completing the form

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.

Here’s my project https://codepen.io/Dagreyby/pen/NWarvdw

One way is using some Javascript:

  • Select urls
  • Grab the <form> html element
  • 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): 
form.addEventListener('submit', (e)=>executeWhenUserSubmitsForm)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.