How to submit to different page based on Text Field Answer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Berkey
    New Member
    • Jan 2011
    • 6

    How to submit to different page based on Text Field Answer?

    Basically I'm trying to have a promotional code
    text field in a html form. If the correct promotional code is entered in the field the form would link to example1.html upon submission. If no code is given then the form would link to example2.html. upon submission.

    Any help would be appreciated.
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    In the HTML form tag don't specify the action url. Add a method for onsubmit in the form. In the function check the value of the text and if it equals to ur desired one set the correct url for action attribute otherwise the other url.

    Sample HTML:

    Code:
    <form id="myForm" name="myForm" method="post" onsubmit="checkThis()">
    <input type="text" id="myText" name="myText" />
    </form>
    JS
    Code:
    function checkThis(){
      var val = document.getElementById('myText').value;
      var myForm = document.getElementById('myForm');
      if(val=="myDesiredValue")
        myForm.action="url1.html";
      else
        myForm.action="url2.html";
    }
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Phil Berkey
      New Member
      • Jan 2011
      • 6

      #3
      That was SUPER helpful Ramanan Kalirajan.

      3 minor questions.

      1. Will the form still send its contents via email if I insert the action=""?

      2. How would I properly add additional promo codes?

      3. Can the function verify if codes are correct or not?

      Thanks for you help!

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        For the Questions

        1) Are you using mail to in the action attribute? otherwise it will be a normal HTTP submission only.

        2) You can have n no of input boxes or select boxes inside the form. That way you can add promo codes

        3) Yes you can verify it in the code.

        Thanks and Regards
        Ramanan Kalirajan

        Comment

        Working...