cvs: phpdoc /en/faq html.xml

From: Date: Tue, 08 Apr 2003 11:31:40 +0000
Subject: cvs: phpdoc /en/faq html.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969352501@lists.php.net to get a copy of this message
sean Tue Apr 8 07:31:40 2003 EDT Modified files: /phpdoc/en/faq html.xml Log: Added Javascript variable example (bug 14527) Index: phpdoc/en/faq/html.xml diff -u phpdoc/en/faq/html.xml:1.19 phpdoc/en/faq/html.xml:1.20 --- phpdoc/en/faq/html.xml:1.19 Fri Jan 24 14:46:14 2003 +++ phpdoc/en/faq/html.xml Tue Apr 8 07:31:40 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.19 $ --> +<!-- $Revision: 1.20 $ --> <chapter id="faq.html"> <title>PHP and HTML</title> <titleabbrev>PHP and HTML</titleabbrev> @@ -190,7 +190,7 @@ ]]> </programlisting> This produces two arrays, MyArray and MyOtherArray, that gets sent - to the PHP script. It's also possible to assign specific keys + to the PHP script. It's also possible to assign specific keys to your arrays: <programlisting role="html"> <![CDATA[ @@ -205,15 +205,15 @@ <para> <note> <para> - Specifying an arrays key is optional in HTML. If you do not specify - the keys, the array gets filled in the order the elements appear in + Specifying an arrays key is optional in HTML. If you do not specify + the keys, the array gets filled in the order the elements appear in the form. Our first example will contain keys 0, 1, 2 and 3. </para> </note> </para> <para> - See also - <link linkend="ref.array">Array Functions</link> and + See also + <link linkend="ref.array">Array Functions</link> and <link linkend="language.variables.external">Variables from outside PHP</link>. </para> </answer> @@ -222,7 +222,7 @@ <qandaentry id="faq.html.select-multiple"> <question> <para> - How do I get all the results from a select multiple HTML tag? + How do I get all the results from a select multiple HTML tag? </para> </question> <answer> @@ -271,6 +271,58 @@ </para> </answer> </qandaentry> + + <qandaentry id="faq.html.javascript-variable"> + <question> + <para> + How can I pass a variable from Javascript to PHP? + </para> + </question> + <answer> + <para> + Since Javascript is (usually) a client-side technology, and + PHP is (usually) a server-side technology, and since HTTP is a + "stateless" protocol, the two languages cannot directly share + variables. + </para> + <para> + It is, however, possible to pass variables between the two. + One way of accomplishing this is to generate Javascript code + with PHP, and have the browser refresh itself, passing spefic + variables back to the PHP script. The example below shows + precisely how to do this -- it allows PHP code to capture screen + height and width, something that is normally only possible on + the client side. + </para> + <para> + <programlisting> +<![CDATA[ +<?php +if (isset($_GET['width']) AND isset($_GET['height'])) +{ + // output the geometry variables + echo "Screen width is: ". $_GET['width'] ."<br />\n"; + echo "Screen height is: ". $_GET['height'] ."<br />\n"; +} +else +{ + // pass the geometry variables + // (preserve the original query string + // -- post variables will need to handled differently) + + echo "<script language=\"javascript\">\n"; + echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}" + . "&width=\" + screen.width + \"&height=\" + screen.height;\n"; + echo "</script>\n"; + exit(); +} +?> +]]> + </programlisting> + </para> + </answer> + </qandaentry> + </qandaset> </chapter>

« previous php.doc (#969352501) next »