title: how to write javascript code within php
body: <p>I have got a form, on clicking the submit button:</p>
  
  <pre><code>&lt;form&gt;
     &lt;h2 style="text-align: center"&gt;* * * PROJECTS * * *&lt;/h2&gt;
  &lt;br&gt;
     &lt;input type="button" name="submit" onclick="document.write('&lt;?php GetCellValues() ?&gt;');" Value="SAVE"&gt;
  &lt;br&gt;
  &lt;/form&gt;
  
  &lt;?php
      function GetCellValues()
      {
          echo("Save");
          var str = '';
          var rows = document.getElementsByTagName('tr');
          var table=document.getElementById("project");
          for (var i=0;i&lt;table.rows[0].cells.length;i++)
          {
              str = str + (table.rows[0].cells[i].innerHTML) + ', ' ;     
          }
          for (var c = 1 ; c &lt; rows.length ; c++)
          {
              str += '\n' + "0" + c + ', ';
              var row = rows[c];
              var inputs = row.getElementsByTagName('input');                
              for (var k = 0 ; k &lt; inputs.length ; k++)
              {
                  str += inputs[k].value + ', ';
              }
          }
      }
  ?&gt;
  
  &lt;?php
  $handle = fopen("data.csv", "w");
  $hide = $_REQUEST['hide'];
  fwrite($handle,$hide);
  
  $file = file('data.csv');
  $lines = count($file);
  
  echo'&lt;table id = "projest" border = "1" cellpadding="2" cellspacing="0" style = "width: 60%; margin-left: auto; margin-right: auto; border-color: brown; background-color:gray;"&gt;';
  echo'&lt;tr cellpadding="100"&gt;
      &lt;th width="15%"&gt;&lt;h3&gt;Sl.No.&lt;/h3&gt;&lt;/th&gt;
      &lt;th width="15%"&gt;&lt;h3&gt;Project Name&lt;/h3&gt;&lt;/th&gt;
      &lt;th width="15%"&gt;&lt;h3&gt;ChangeDate&lt;/h3&gt;&lt;/th&gt;
      &lt;th width="15%"&gt;&lt;h3&gt;Changed By&lt;/h3&gt;&lt;/th&gt;
  &lt;/tr&gt;';
  for ($i=1; $i&lt;$lines; $i++) 
  {
  
    $part = explode(',', $file[$i]);
  
    echo'&lt;tr&gt;
      &lt;td align= "center" width="5%"&gt;'.$part[0].'&lt;/td&gt;
      &lt;td align= "center" width="25%"&gt;&lt;input type="text" value='.$part[1].'&gt;&lt;/td&gt;
      &lt;td align= "center" width="25%"&gt;&lt;input type="text" value='.$part[2].'&gt;&lt;/td&gt;
      &lt;td align= "center" width="25%"&gt;&lt;input type="text" value='.$part[3].'&gt;&lt;/td&gt; 
    &lt;/tr&gt;';
  }
  echo'&lt;/table&gt;'; 
  ?&gt;
  </code></pre>
  
  <p>But not able to submit the form, if I call the javascript code on onClick, it works.what is the problem in this code, Is there any work around for this?</p>