Re: Accessing Variable !!!
| From: | Richard Lynch | Date: | Wed, 12 Sep 2001 05:05:00 +0000 |
| Subject: | Re: Accessing Variable !!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-66995@lists.php.net to get a copy of this message | ||
PHP lives on the server.
JavaScript lives on the browser.
Consider the sequencing of events:
1: Browser sends GET request
2: Apache begins processing request, decides to invoke PHP
3: PHP begins processing, starts sending out HTML (or other data)
4: Apache passes through PHP's HTML/data
5: Browser begins receiving HTML/data
6: Apache and PHP finish sending data and CLOSE CONNECTION
7: Browser displays HTML and executes JavaScript
By the time your JavaScript runs, PHP is long-gone.
The only way to get data back to PHP is to send a whole 'nother HTTP request
from JavaScript to get a whole 'nother URL.
This is not generally useful for humanly bearable interaction time-wise, but
is occasionally useful.
--
WARNING richard@zend.com address is an endangered species -- Use
ceo@l-i-e.com
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Girish P <girishp@aztec.soft.net>
Newsgroups: php.general
To: <php-general@lists.php.net>
Sent: Monday, September 10, 2001 10:37 AM
Subject: Accessing Variable !!!
Hi,
I am trying to use value of the text box for the querying ..The
query is defined with in the a javaScript .
I am not able to get the Value.. inside the function.. However
"document.form.text.value" is getting the value.
How do we assign the value of javscript to PHP??? Is there a better way
,,,
Php is as follows:
<html>
<head>
<title>Search result</title>
</head>
<body bgcolor="#fffff0">
<?php
echo "<Script Language = \"JavaScript\">\n";
echo "function getNames()\n";
echo "{\n";
echo "alert(\"Inside the FUcntion\");\n";
$connection = mssql_connect("girishp", "sa", "") or die
("could not connect to server.");
$db = mssql_select_db("AZADMINGROUP", $connection) or die
("Could not select database");
$sql_employee = "Select E_Number,E_First_Name,E_Last_Name from
T_Employee where E_First_Name = \"$searchName\"";
echo "alert(document.searchEmpl.searchName.value);\n";
$result_employee = mssql_query($sql_employee, $connection) or die
("Coule not execute"); $count = 1;
while($row = mssql_fetch_array($result_employee)) {
$ENo = $row["E_Number"];
$val = $row["E_First_Name"];
$val = $val . $row["E_Last_Name"];
#echo "var val = document.searchEmpl.searchresult;\n";
$val = $val . " ( " . $ENo . " )";
echo "document.searchEmpl.searchResult.options[$count].value =
'$val';\n";
echo "document.searchEmpl.searchResult.options[$count].text =
'$val';\n";
$count++;
}
echo "}\n";
echo "</Script>\n";
echo "<form name=\"searchEmpl\" method=\"POST\"
action=\"Employee_Details.php\">\n";
echo "<h2><font color=\"#CC6699\">Search
:</font></h2>\n";
echo "<hr color=\"#CC6699\">\n";
echo "<p><font color=\"#CC6699\"><b>Employee Name :
</b></font><input type=\"text\" name=\"searchName\"
size=\"20\"> \n";
echo "<input type=\"button\" value=\"Search\"
name=\"searchButton\"
onClick=\"getNames();\"></p>\n";
echo "<p align=\"left\"><select size=\"1\"
name=\"searchResult\">\n";
echo "<option>Search Result</option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "<option></option>\n";
echo "</select> <input type=\"submit\" value=\"Show
Details\" name=\"B3\">
</p>\n";
echo "</form>\n\n";
?>
</body>
</html>
TIA
Girish