title: Using php variable in javascript if-statement
body: <p>I would like to pass on a <code>$_POST['foo']</code> variable to a JavaScript variable while I am using a php if- statement. But its not working. Any suggestions on how to make it run?</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['foo']))    
  {    
  ?&gt;
  &lt;script&gt;
  var jFoo= &lt;?php echo json_encode($_POST['foo']); ?&gt;;
  &lt;/script&gt;
  &lt;?
  }
  
  
   else {
      ...
      }
      ?&gt;
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>This is weird: 
  I was actually trying to make the code run like this (this wasnt working):
   
  
  <pre><code>if(isset($_POST['foo']))    
  {    
  ?&gt;
  &lt;script&gt;
  var jFoo= &lt;?php echo json_encode($foo); ?&gt;;
  &lt;/script&gt;
  &lt;?
  }
  else {
  ...
  }
  </code></pre>
  
  <p>However, when I just did this, it worked:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['foo']))    
  {    
  ?&gt;
  &lt;script&gt;
  var jFoo= &lt;?php echo json_encode($_POST['foo']); ?&gt;;
  &lt;/script&gt;
  &lt;?
  }
  else {
  ...
  }
  </code></pre>
  
  <p>Any ideas why?</p>