Hi.
This java script dont work on the second dropdown.
The first dropdown rewrights the URL with param. cat.
The problem is that the second time it dos not pick up the town param.
Please help me im not a javascript persson but trying.....
//Mikael
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='image_upload.php?cat=' + val ;
}
function reload2(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
txt1=val;
txt2="&town=";
txt3=txt1+txt2;
txt4=txt3;
self.location='image_upload.php?cat=' + txt4 ;
}
</script>
</head>
<?php
include('configs/dbconfig.php');
//Connect to your rating database
$servername = $db_host;
$dbuser = $db_user;
$dbpassword = $db_pass;
$dbname = $db_name;
connecttodb($servername,$dbname,$dbuser,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
$cat2=$_GET['cat'];
@$cat=$_GET['cat'];
@$town=$_GET['town'];
$quer2=mysql_query("SELECT DISTINCT name,cid FROM categories order by name");
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT town FROM files_video where vcategs='0,$cat,0' and town >'' union
SELECT DISTINCT town FROM files_image where vcategs='0,$cat,0' and town >'' order by town");
}else{$quer=mysql_query("SELECT DISTINCT town FROM files_video order by town"); }
echo "<td align='left' valign='top'></td>
<td class='nopad'>
<table cellpadding=1 cellspacing=0 border=0>
<tr><td width='20%' align='left'>Ett land:</td><td>
<select class='ff' name='cat' onchange=\"reload(this.form)\"><option value=''>Välj ett land</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cid']==@$cat){echo "<option selected value='$noticia2[cid]'>$noticia2[name]</option>"."<BR>";}
else{echo "<option value='$noticia2[cid]'>$noticia2[name]</option>";}
}
echo "</select></td></tr>";
$cat= $_POST['cat'];
echo "$cat2 cat2";
echo "<tr><td width='20%' align='left'>En stad:</td><td>
<select class='ff' name='town' onchange=\"reload2(this.form)\"><option value='$cid'>Välj en stad</option>";
if ($cat2 !=''){
while($noticia = mysql_fetch_array($quer)) {
if($noticia['town']==@$town){echo "<option selected value='$noticia[town]'>$noticia[town]</option>"."<BR>";}
else{echo "<option value='$noticia[town]'>$noticia[town]</option>";}
}
}
echo "</select></td></tr>";
$town=$_POST['town'];
echo "$town town";
echo "<tr>
<td width='20%' align='left'>Ny stad: :</td><td><input class='ff' type='text' name='town2'></td></tr>";
?>