title: Using Javascript for setting PHP variable as HTML text field's value
body: <p>I am a learning Javascript and PHP, I am trying to do this ,
  I have stored some variables in a PHP session, i am trying to set the values present in the session as the values in the form's input field, i have used javascript for that purpose,</p>
  
  <p><strong>PHP :</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;link rel='stylesheet' type='text/css' href='http://localhost/Matrix/frameCSS.css' /&gt;
      &lt;script lang='text/javascript' src='http://localhost/Matrix/gd.js'&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php
          // ------- --------- -------- -------- ------
          $debug=true;
          dBug("Started Code Execution ... ");
          function dBug($text)
          {
              global $debug;
              if($debug) { echo "&lt;p class='status'&gt;debug : $text&lt;/p&gt;"; }
              else { return; }
          }
          // ------ ----------- ------------ -----------
          $db = mysqli_connect("127.0.0.1","user","xyz","sample");
          if(mysqli_connect_errno())
          {
              die(mysqli_connect_error());
          }
          session_start();
          if($_SESSION['is_open']==true)
          {
              $username = $_SESSION['username'];
              dBug('retreived username &gt; '.$username);
          }
      ?&gt;
  
      &lt;table class="content"&gt;
          &lt;form method="POST" action="http://localhost/gen_det.php" onload="load_data()"&gt;
             &lt;tr&gt;
                 &lt;td&gt;
                      Full Name : 
                 &lt;/td&gt;
                 &lt;td&gt;
                      &lt;input type="text" class="txtbox" id='name'/&gt;
                 &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                 &lt;td&gt;
                      Age : 
                 &lt;/td&gt;
                 &lt;td&gt;
                      &lt;input type="text" class="txtbox" id='age' /&gt;
                 &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                  &lt;td&gt;
                      &lt;p class='status' id='status'&gt;&amp;nbsp;&lt;/p&gt;
                  &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                 &lt;td colspan="2" align='center'&gt; 
                      &lt;input type="submit" class="btn" onclick="return validateData();" value="save" /&gt; 
                      &lt;input type="button" class="btn" onclick="redirect()" value="cancel" /&gt; 
                 &lt;/td&gt;
             &lt;/tr&gt;
          &lt;/form&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Javascript :</strong></p>
  
  <pre><code>function load_data()
  {
   var name = document.getElementById('name');
   var age = document.getElementById('age'); 
   name.value = " &lt;?php echo ''.$_SESSION['username']; ?&gt; ";
   age.value = " &lt;?php echo ''.$_SESSION['username']; ?&gt; ";
  }
  </code></pre>
  
  <p>This page is actually inside a iframe in another page (if that is important). When I open this page, it opens , but the values aren't filled in the text fields. What have I done wrong ?</p>