PHP javascript Client server data exchange
<p>1.
I am taking input from user in a text area and saving that input in a file on server in particular directory. I am doing this using below code. </p>

<p>2.
Now after that i want to take this newly created filename in a variable to which i can use in Javascript for validations at client side in a HTML file. 
After it in the same HTML file I will send this data to a server 'calling a cgi file' - using url and the variables in querystring'.</p>

<p>Below is the code which is doing task 1 well. But i want to do ALL these tasks using a single submit button. Can anyone please help me out. M stuck badly in this!</p>

<pre><code>&lt;?php //test.php
$file = 'orders'.getmypid();
$FileHandle = fopen($file, 'x+');
$FileHandle = fopen($file, 'w') or die("can't open file");
fclose($FileHandle);
if(isset($_POST['submit'])){
$area=$_REQUEST['area'];
$fd=fopen("$file","w+");
fwrite($fd,$area);
fclose($fd);
$file_contents=file_get_contents("$file");
print $file_contents;
}
?&gt;



&lt;html&gt;
&lt;HEAD&gt;
&lt;TITLE&gt; Data Status &lt;/TITLE&gt;
&lt;style type=text/css&gt;
body {
font-family: ARIAL;
font-size: 70%;
color: BLACK;
}
table { border-collapse:collapse; }
&lt;/style&gt;
&lt;/HEAD&gt;
&lt;BODY background="Bckgrnd.jpg"&gt;

&lt;hr&gt;&lt;br&gt;
&lt;center&gt;&lt;font face="Monotype Corsiva" size =5&gt; Data Status &lt;/font&gt;&lt;/center&gt;&lt;br&gt;&lt;hr&gt;
&lt;form method="post" action="test.php"&gt;
&lt;table border=1 bordercolor=BLACK align=center width =50%&gt;
&lt;tr align=center&gt;
&lt;th colspan = 2&gt;PLEASE ENTER THE BELOW DETAILS&lt;/th&gt;
&lt;/tr&gt;
&lt;tr align = center&gt;
&lt;th&gt;DATA: &lt;/th&gt;

&lt;td&gt;&lt;textarea cols=40 rows=10 name="area"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/Table&gt;
&lt;tr align = center&gt;
&lt;td&gt;&lt;input type="submit" name="submit" value="submit"&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/Form&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>
