Здравейте,
имам три селекта от които избирам област, район и подрайон. Проблема е че като избера напр. София не ми изкарва кварталите, а всичко от subcategory. onchange не работи.
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
///////////// 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=$GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id= " .$cat. " order by subcategory");
}else{$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); }
////////// 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=$GET['subcat']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id= " .$cat3. " order by subcat2");
}else{$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"); }
////////// end of query for third subcategory drop down list box ///////////////////////////
$site .= " <form name=\"f1\" action=\"index.php?m=" . $m . "&style=" . $style . "\" method=\"post\" enctype=\"multipart/form-data\">\n";
$site .= " <p>Град/Област<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"cat\" onchange=\"reload(this.form) \" value=\"" . ((isset($_POST['cat'])) ? $_POST['cat'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете град/област</option>\n";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cat_id']==@$cat){
$site .= "<option selected value=\"" .$noticia2['cat_id'] . "\">" .$noticia2['category'] ."</option>"."<BR>";}
else{
$site .="<option value=\"" .$noticia2['cat_id'] . "\">" . $noticia2['category'] ."</option>";}
}
$site .= "</select>\n";
$site .= " </p>\n";
$site .= " <p>Район<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"subcat\" onchange=\"reload3(this.form)\" value=\"" . ((isset($_POST['subcat'])) ? $_POST['subcat'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете район</option>\n";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['subcat_id']==@$cat3){
$site .= "<option selected value=\"" . $noticia['subcat_id']. ">" .$noticia['subcategory'] . "</option>"."<BR>";}
else{
$site .= "<option value=\"" . $noticia['subcat_id']. ">" .$noticia['subcategory'] . "</option>";}
}
$site .="</select>\n";
$site .= " </p>\n";
$site .= " <p>Подрайон<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"subcat3\" value=\"" . ((isset($_POST['subcat3'])) ? $_POST['subcat3'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете район</option>\n";
while($noticia = mysql_fetch_array($quer3)) {
$site .= "<option value=\"" . $noticia['subcat2']. "\">" .$noticia['subcat2']. "</option>";
}
$site .="</select>\n";
$site .= " </p>\n";
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
location.href = "index.php?m=" + m + "&style=" + s + "&cat=" + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
location.href = "index.php?m=" + m + "&style=" + s + "&cat=" + val + "&cat3=" + val2 ;
}
имам три селекта от които избирам област, район и подрайон. Проблема е че като избера напр. София не ми изкарва кварталите, а всичко от subcategory. onchange не работи.
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
///////////// 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=$GET['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id= " .$cat. " order by subcategory");
}else{$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); }
////////// 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=$GET['subcat']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id= " .$cat3. " order by subcat2");
}else{$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"); }
////////// end of query for third subcategory drop down list box ///////////////////////////
$site .= " <form name=\"f1\" action=\"index.php?m=" . $m . "&style=" . $style . "\" method=\"post\" enctype=\"multipart/form-data\">\n";
$site .= " <p>Град/Област<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"cat\" onchange=\"reload(this.form) \" value=\"" . ((isset($_POST['cat'])) ? $_POST['cat'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете град/област</option>\n";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cat_id']==@$cat){
$site .= "<option selected value=\"" .$noticia2['cat_id'] . "\">" .$noticia2['category'] ."</option>"."<BR>";}
else{
$site .="<option value=\"" .$noticia2['cat_id'] . "\">" . $noticia2['category'] ."</option>";}
}
$site .= "</select>\n";
$site .= " </p>\n";
$site .= " <p>Район<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"subcat\" onchange=\"reload3(this.form)\" value=\"" . ((isset($_POST['subcat'])) ? $_POST['subcat'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете район</option>\n";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['subcat_id']==@$cat3){
$site .= "<option selected value=\"" . $noticia['subcat_id']. ">" .$noticia['subcategory'] . "</option>"."<BR>";}
else{
$site .= "<option value=\"" . $noticia['subcat_id']. ">" .$noticia['subcategory'] . "</option>";}
}
$site .="</select>\n";
$site .= " </p>\n";
$site .= " <p>Подрайон<br />\n";
$site .= " </p>\n";
$site .= "<select name=\"subcat3\" value=\"" . ((isset($_POST['subcat3'])) ? $_POST['subcat3'] : '') . "\" >
<option value=\"0\" selected=\"selected\">Изберете район</option>\n";
while($noticia = mysql_fetch_array($quer3)) {
$site .= "<option value=\"" . $noticia['subcat2']. "\">" .$noticia['subcat2']. "</option>";
}
$site .="</select>\n";
$site .= " </p>\n";
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
location.href = "index.php?m=" + m + "&style=" + s + "&cat=" + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
location.href = "index.php?m=" + m + "&style=" + s + "&cat=" + val + "&cat3=" + val2 ;
}