Re: pass javascript variable to php without submit or reload

From: Date: Mon, 12 Nov 2001 00:51:33 +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-74202@lists.php.net to get a copy of this message
Hi Richard, I can workaround the problem by using switch in changebuilding() JS and assign a number to $variable, but the program is too long if I have 10 or 20 options. Another way that I can think of that is putting action=demo1.php in the form and using js to submit the form when I change the option. I am ok with dynamic update content by using JS. thank for your reply "Richard S. Crawford" wrote: > > 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 > > --

« previous php.general (#74202) next »