websurfer 0 Junior Poster in Training

Hello, All:

I have another problem with this second-menu-selection-based on first menu script... whcih I want to implement into tour site... firsts menu shows countries, second menu shows cities related to selection from first menu. So ideally, when I bring an item to update and it already has Brazil as country and Sao Paulo as its city, it should already show both entries as "selected" in each corresponding menu.

I picked this off the web somewhere and here it uses javascript to switch selections from db and it does work pretty well, ECXEPT I need it to remember the entered data from within the DB that is to be updated... right now, when I bring this up to update all my other text, area fields info show ok, but the menu defaults to its "Select One" option as selected as opposed to showing "Brazil" already chosen...

Here is the Javascript code that goes on head section, and below is the 2-menu snippet.


Appreciate any help!!

//// HERE FOLLOWS JAVASCRIPT/////

<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd-modified.php?cat=' + val ;
}

</script>

//// HERE FOLLOWS 2-MENU SCRIPT/////

<?

@$cat= $_GET; // Use this line or below line if register_global is off
//@$cat=$HTTP_GET_VARS; // Use this line or above line if register_global is off

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT category_name,category_id FROM item_category order by category_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/////
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT city_name FROM item_subcategory where country_code=$cat order by city_name");
}else{$quer=mysql_query("SELECT DISTINCT city_name FROM item_subcategory order by city_name"); }
////////// end of query for second subcategory drop down list box ///////////////////////////

////////// Starting of first drop downlist /////////
echo "<select name='cat' id='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2==@$cat){echo "<option selected value='$noticia2[category_name]'>$noticia2[category_name]</option>"."<BR>";}
else{echo "<option value='$noticia2[category_id]'>$noticia2[category_name]</option>";}
}
echo "</select> <br><br>";
////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////
echo "<select name='subcat' id='subcat' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[city_name]'>$noticia[city_name]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.