title: Sending a variable from javascript to php to be checked and back to javascript
body: <p>I am using JavaScript to validate my form. It's basic validation. The step I am having problems with it sending the synum variable via post from java script to my php page valid_synum.php where I do a pdo look up to check if that synum exists or not then I echo a 1 or a 0 based on the result. I want the java script to take that result and either send an alert error or if ok allow the form to submit. Here is the javascript I have. As far as I can tell the POST call </p>
  
  <blockquote>
    <p>$.post("valid_synum.php", { synum: synum },</p>
  </blockquote>
  
  <p>is never called up. I placed a test in the php page and the test never gets activated from the script. It works fine if I load the php directly in a browser. </p>
  
  <p>Any help would be greatly appreciated. </p>
  
  <pre><code>&lt;script&gt; 
  function isNumber(input)
  {
  
  return (input - 0) == input &amp;&amp; (input+'').replace(/^\s+|\s+$/g, "").length &gt; 0;
  }
  
  function checkForm(f)
  {
       if (f.elements['worknum'].value != "") 
      { 
       if ((isNumber(f.elements['worknum'].value)) == false)
          {
          alert("The Work Order Number is not valid")
          return false;
          }
          var chars = 6;
      if((f.elements['worknum'].value).length != 6)   
          {
          alert("The Work Order Number is not 6 digits")
          return false;
          }
      }
  
      if (f.elements['synum'].value == "") 
      {
          alert("Please Enter the Store Number");
          return false;
      }
       if (f.elements['worknum'].value == "") 
      {
          alert("Please Enter the Work Order Number");
          return false;
      }
  
      if (f.elements['synum'].value != "")
          {
          //get the username  
          var synum = (f.elements['synum'].value);  
  
  
          $.post("valid_synum.php", { synum: synum },  
              function(result){  
  
                       //if the result is 1  
                  if(result == 1){  
                      //do nothing valid synum 
                      alert("Good") 
                      return false; 
                  }else{  
                      //show that the username is NOT available  
                      alert("The store number is NOT valid. Please Enter full store number") 
                      return false; 
                  }  
          }); 
  
      }   
  
      else
      {
          f.submit();
          return false;
      }
  
  }
  
  
  &lt;/script&gt; 
  </code></pre>
  
  <p>Here is my php page code:</p>
  
  <pre><code>$id=$_POST['synum'];
  
  try{
  $conn = new PDO( "sqlsrv:Server= $eautoserver ; Database = $eautodb ", $eautouser,    $eautopwd);
     $conn-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  
  $stmt = $conn-&gt;prepare('SELECT * FROM vw_DCR_Web_Customer_Query WHERE CustomerNumber= :id');
   $stmt-&gt;execute(array('id' =&gt; $id));
  $row = $stmt-&gt;fetch();
  
  } catch(PDOException $e) {
  echo 'ERROR: ' . $e-&gt;getMessage();
  }
  
  if ($row){
  echo 1;
  $email_body="1";
  }else{
  echo 0;
  $email_body="0";
  }
  </code></pre>