Request Dev Services ยป / Notes /

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.

About the Author
Cameron Cashwell Web Developer
I build websites, web apps, and software. Wanna work together? Let's chat about your project!

Leave a Reply

Be the First to Comment!

Notify of