javascript two action needed on submit

Discussion in 'JavaScript' started by jacka, Oct 28, 2008.

  1. #1
    Hi
    I have a form that needs post code checking.
    On successful completion of the postcode check I wish to open another window (not a new one).
    it sounds simple but not being javascript competent, its driving me crazy.
    I have copied the postcode check from some one else:
    
    
    function postit(){ //check postcode format is valid
     test = document.details.pcode.value; size = test.length
     test = test.toUpperCase(); //Change to uppercase
     while (test.slice(0,1) == " ") //Strip leading spaces
      {test = test.substr(1,size-1);size = test.length
      }
     while(test.slice(size-1,size)== " ") //Strip trailing spaces
      {test = test.substr(0,size-1);size = test.length
      }
     document.details.pcode.value = test; //write back to form field
     if (size < 6 || size > 8){ //Code length rule
      alert(test + " is not a valid postcode - wrong length");
      document.details.pcode.focus();
      return false;
      }
     if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
       alert(test + " is not a valid postcode - cannot start with a number");
       document.details.pcode.focus();
       return false;
      }
     if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
       alert(test + " is not a valid postcode - alpha character in wrong position");
       document.details.pcode.focus();
       return false;
      }
     if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
       alert(test + " is not a valid postcode - number in wrong position");
       document.details.pcode.focus();
       return false;
      }
     if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
       alert(test + " is not a valid postcode - number in wrong position");
       document.details.pcode.focus();
       return false;
      }
     if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
       alert(test + " is not a valid postcode - no space or space in wrong position");
       document.details.pcode.focus();
       return false;
       }
     count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
     if (count1 != count2){//only one space rule
       alert(test + " is not a valid postcode - only one space allowed");
       document.details.pcode.focus();
       return false;
       
      }
      return true;
    
    }
    //  End -->
    </script>
    
    
    Code (markup):
    my calling line is:
    
     <input class="submit1" type="SUBMIT"  value="Submit Info. " onclick="postit()" name="Button"  > 
    Code (markup):
    and my form action call is :
    
    <FORM name="details" ENCTYPE="multipart/form-data" ACTION="../this/that.php"
                 METHOD="POST"> 
    Code (markup):
    All I need is teh post code to be checked for validity and then take me to that.php page, wihtout opeing a new page.

    many thanks for your help.
     
    jacka, Oct 28, 2008 IP
  2. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi
    Solved it.
    used this instead:
    
    <FORM name="details" ENCTYPE="multipart/form-data" ACTION="that/this.php" onsubmit="return postit()"
                 METHOD="POST"> 
    Code (markup):
    thx
     
    jacka, Oct 28, 2008 IP