Redirect to pages based on input form field value (JS tips)

A quick JavaScript / jQuery snippet for your soul. Validate input form field value based on specific correct text value, if correct redirect to correct page; and if wrong, to error page.

function checkAnswer(){
      var response = document.getElementById('answer').value; // form elem
      if (response == "correctanswer") // check for this value
          location = ''; 
          location = ''; // incorrect if not found
      return false;

If you want to use the hash URL parameter for your ‘correct’ and ‘incorrect’ pages – check out my previous JS post for use of hash.

Published by


I’m Cameron Cashwell, I’ve been a Web Developer for 6+ years. I’m always on the look out for exciting new projects and ideas. Wanna work together?

Leave a Reply

Be the First to Comment!

Notify of