Re: Query a databaes without refreshing the page

From: Date: Mon, 21 Apr 2003 18:06:38 +0000
Subject: Re: Query a databaes without refreshing the page
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144681@lists.php.net to get a copy of this message
You need to create javascript code that will do it for you. You can start with this code, filter is the name of the main select box, subfilter is the name of the dependent select box, subfilter values are in the form mainfiltervalue_subfiltervalue, so if USA is <option value="55">USA</option>, states would be <option value="55_334">Arizona</option> and so on. You may want to call refilter() when the page loads so the subfilter is cleared var subfiltervals = new Array(); var subfiltertexts = new Array(); function refilter() {
     var f = document.queryForm.filter; // change filter to whatever is the select's name
var sf = document.queryForm.subfilter; // same for this var i=0; var count; var reg;
     if(subfiltervals.length == 0) {
       while(sf.length) {
           subfiltervals[i]=sf.options[0].value;
           subfiltertexts[i++]=sf.options[0].text;
           sf.options[0] = null;
       }
} else {
       sf.length = 0;
} reg = new RegExp(); reg.compile('^' + f.options[f.selectedIndex].value + '_'); // the underscore is the split character, you can change it
     count=subfiltervals.length;
     for(i=0; i <count; i++ ){
       if(reg.test(subfiltervals[i])) {
           sf.options[sf.length]= new Option(subfiltertexts[i],subfiltervals[i]);
       }
} } Fernando Shayani wrote:
Is there any way that I can do this: I have a page with 2 combo boxes. The first one is the COUNTRY. When the page loads, the PHP get the list of countrys from the MySQL and insert the values on the combo box. Then, I select on the combo, the country, for example, USA. AFTER THIS, without refreshing the page, I need that the second combo box automatic loads the list of cities of USA. Is there any way to do this?


« previous php.general (#144681) next »