Re: pass javascript variable to php without submit or reload

From: Date: Mon, 12 Nov 2001 00:14:48 +0000
Subject: Re: pass javascript variable to php without submit or reload
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74201@lists.php.net to get a copy of this message
You can't do that without reloading the page; the PHP is parsed but once as the page is loaded. Once the page is loaded, it's up to the browser to deal with, and PHP washes its hands of the page. So the only way to get new content from a PHP script is to reload the page. It is possible to update the list in a select form element dynamically based on input from other JavaScript variables, but it has to be done entirely in JavaScript; you need to load every value into your changebuilding() function and rebuild the script from there. Check out
        http://javascript.internet.com/forms/auto-drop-down.html
for an example of how you might be able to adjust the contents of a select drop-down list dynamically in JavaScript. At 04:04 PM 11/11/2001, Phieu Huynh wrote:
<script language=javascript> function changebuilding (which) {
     sel_var = which.selectedIndex
     <?
       $sql_query = "select distinct room
                     from general.room_info
                     where building='$variable' group by level asc";
       $sql_result = mysql_query($sql_query) or die (" Can't execute the
query");
       $i=0;
       while ($row = mysql_fetch_array($result_sec_level))
             print ("ar[".$i++."] = \"".$row[0]."\";\n");
     ?>
    for (i=0; i < ar.length; i++) {
        option = new Option(ar[i])
        document.myform.room.options[i]=option
} } </script> <body> <form name=myform> Building : <select name=building onchange=changebuilding(this) >
                <option>1</option>
                <option>2</option>
                <option>3</option>
             </select>
Room : <select name=room >
         </select>
</form> </body> I can pass the variable in building to $variable by submit button but I want to pass the sel_var variable to $variable and dynamic update the content in room. -- phil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
Sliante, Richard S. Crawford http://www.mossroot.com mailto:rscrawford@mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford "It is only with the heart that we see rightly; what is essential is invisible to the eye." --Antoine de Saint Exupéry "Push the button, Max!"

« previous php.general (#74201) next »