title: How to assign a PHP variable value to JavaScript variable
body: <p>In this code which I am posting i have one problem. I want my PHP variable to be stored in JavaScript variable but it shows error. The code is below.</p>
  
  <pre><code>&lt;?php
      $name="anurag singh";
  
      echo '
          &lt;html&gt;
              &lt;head&gt;
              &lt;script type="text/javascript" src="jquery-2.0.2.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript"&gt;
                  $(document).ready(function(){
                      var name1=.$name.";"
                      $.post("main_page.php",{input1: name1}, function(msg){
                          alert("hi "+msg);
                      });
                  });
              &lt;/script&gt;
              &lt;/head&gt;
  
              &lt;body&gt;
                  &lt;h1&gt;This is the demo!&lt;/h1&gt;
                  &lt;h2&gt;In echo we can add more than one statements&lt;/h2&gt;
              &lt;/body&gt;
          &lt;/html&gt;
      ';
  ?&gt;
  </code></pre>
  
  <p>Now when I am assigning <code>$name</code> to the variable <code>name1</code> than I get an syntax error. Please let me know what changes I have to make. So that I get the value of the PHP variable <code>$name</code> stored in JavaScript variable <code>name1</code>.</p>