How to validate these form fields with JavaScript?

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

    How to validate these form fields with JavaScript?

    Hello I'm trying to do two fold with this script.
    1. Add a additional promotion code that links to a 2nd .html location. Else goes to a 3rd location.

    2. Verify the two promotional codes are correct or incorrect with Alert function via the check it button.

    Script below. Any help would be appreciated!

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    <!--
    function checkThis(){
      var val = document.getElementById('myText').value;
      var myForm = document.getElementById('myForm');
      if(val=="promocode1")
        myForm.action="url1.html";
      else
        myForm.action="url2.html";
    }
    //-->
    </script>
    
    </head>
    
    <body>
    <form id="myForm" name="myForm" method="post" onsubmit="checkThis()">
      <p>
        <input type="text" id="myText" name="myText" />
        <input name="button" type="button" value="Check It"/>
      </p>
      <p>
        <label>
        <input type="submit" name="Submit" value="Submit" />
        </label>
    </p>
    </form>
    </body>
    </html>
    Last edited by Dormilich; Jan 20 '11, 06:50 AM. Reason: please use [code] [/code] tags when posting code
Working...