I'm sooo stuck on this problem I've stopped believing that it is possible, perhaps someone can help.
I have a three tiered dynamic drop down menu which is being populated from my database. (I'll post the code below) Its works with Javascript which tells it to reload the page when an option in the drop down is selected. This is all fine and works a treat.
My problem happens when I already have a variable in the address bar, for instance "?id=345" as you can image when the page is reloaded this variable is lost and the page makes no sense.
I would like to know how to keep my original "?id=345" and still have the page reload with the variables passed by the drop down menu.
Heres some code to make things clearer.
First the request from the DB for the drop down values:
/////// NEW THREE TIER DROP DOWN ///////////////////
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT longhaulcountry_name,longhaulcountry_code FROM longhaul_countries order by longhaulcountry_name");
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
//$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
if(isset($country) and strlen($country) > 0){
$quer=mysql_query("SELECT DISTINCT region_code,country_code,region_name FROM regions where country_code = '$country' order by region_name");
}else{$quer=mysql_query("SELECT DISTINCT region_code,country_code,region_name FROM regions order by region_name"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3/////
//$cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if your global variable is off
if(isset($region) and strlen($region) > 0){
$quer3=mysql_query("SELECT DISTINCT locality_code, region_code,locality_name FROM locality where region_code='$region' order by locality_name");
}else{$quer3=mysql_query("SELECT DISTINCT locality_code, region_code,locality_name FROM locality order by locality_name"); }
////////// end of query for third subcategory drop down list box ///////////////////////////
///////// END //////////////////////////////////////
Next the code for the drop down menus:
////////// Starting of first drop downlist /////////
echo "<select name='country' onchange=\"reload(this.form)\"><option value='$acc_country_code'>$temp</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['longhaulcountry_code']==@$country){echo "<option selected value='$noticia2[longhaulcountry_code]'>$noticia2[longhaulcountry_name]</option>"."<BR>";}
else{echo "<option value='$noticia2[longhaulcountry_code]'>$noticia2[longhaulcountry_name]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='region' onchange=\"reload3(this.form)\"><option value='$acc_region_code'>$tregion_name</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[region_code]'>$noticia[region_name]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
////////// Starting of third drop downlist /////////
echo "<select name='locality' ><option value='$acc_locality_code'>$tlocality_name</option>";
while($noticia = mysql_fetch_array($quer3)) {
echo "<option value='$noticia[locality_name]'>$noticia[locality_name]</option>";
}
echo "</select>";
And finally this is the Javascript that reloads the page. I'm not too sharp with JS but I was hoping that I could say something like :
var val3="<?print $acc_id;?>";
and incorporate it into the line whic has the self.location value.
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.country.options[form.country.options.selectedIndex].value;
self.location='editlonghaul_accomodation.php?country=' + val ;
}
function reload3(form)
{
var val=form.country.options[form.country.options.selectedIndex].value;
var val2=form.region.options[form.region.options.selectedIndex].value;
self.location='editlonghaul_accomodation.php?country=' + val + '®ion=' + val2 ;
}
</script>
Anyway thats my problem , any help at all would be greatly appreciated.
Thanks