faqts : Computers : Programming : Languages : PHP : Not Quite PHP : Javascript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 34 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes


How do you pass a URL ?query via javascript function ?

Jan 28th, 2000 01:37
Allan Taylor,

The URL query in the form <filename?query doesn't pass the referenced 
variables to a new file via a javascript function.  It loses state and 
instead of passing "100" for example it passes the string "$query".
To preserve state the referenced variable needs to saved as a text file 
and then retrieved in the new document by using the following code.
In the <head> section  of the calling file is the following javascript 
function doSubmit($ref)
location.href = "filename?selected =$ref"; 
IF(ISSET($selected)) {  /* If a value has been passed */
$ref = $selected   0; // converts a string into an integer
fputs($fp, $ref);              // Write the value of $ref to ref.txt 
$fp = fopen("ref.txt", "w");   // Open a file pointer 
fclose($fp);                   // Closes file
The following script opens a new file automatically by calling the 
javascript function in the <head>
	echo "<SCRIPT LANGUAGE=\"JavaScript\">";
	echo "doSubmit($ref)";
	echo "</script>";
In the new file the text file is recovered and passed into a variable
IF(ISSET($selected))  /* If there has been given a value for selected 
product */
{ // begin IF $ref set 
Echo " The selected item = $selected";
$fp = fopen("ref.txt", "r");   // Open a file pointer 
$item = fgets($fp, 4096);  // Read the value of ref.txt into a variable 
fclose($fp); 			// Close the file pointer