I'm trying to create a simple navigation script. It allows you to select a region. Once region is selected another list opens up and you can select a city within that region. It all works fine, you can change cities freely and url updates correctly. BUT if you have a city selected and want to re-select the region, the city id stays in the url which messes up my page.
Some examples:
http://192.168.2.16/Seznam.php?IdR=1
http://192.168.2.16/Seznam.php?IdR=1&IdM=101
These two are correct urls, region 1 and city 1 in region 1.
If you now change the region you will get this.
http://192.168.2.16/Seznam.php?IdR=4&IdM=101
Which means region 4 and city 1 in region 1. It should set IdM (city id) to 0 or remove it completely.
Any ideas?
Here's the code I'm using.
Expand|Select|Wrap|Line Numbers
- <form method="get" action="Seznam.php" id="Spremeni">
- <fieldset>
- <select class="Polje" name="IdR" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
- <option value="0">Izberi Regijo</option>
- <?PHP
- $Regija = Zavaruj($_GET['IdR']);
- $Mesto = Zavaruj($_GET['IdM']);
- // $Mesto_2 = substr($Mesto,0,1);
- $Poizvedba_Regije = mysql_query("SELECT * FROM Regije ORDER BY Id");
- while ($Izpis_Regij = mysql_fetch_assoc($Poizvedba_Regije))
- {
- ?>
- <option value="<?PHP echo $Izpis_Regij['Id'] ?>" <?PHP if ($Regija == $Izpis_Regij['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Regij['Ime'] ?></option>
- <?PHP
- }
- ?>
- </select>
- <?PHP
- if (!$Regija)
- {
- echo "</fieldset></form>";
- }
- if ($Regija)
- {
- ?>
- <select class="Polje" name="IdM" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
- <option value="0">Izberi Mesto</option>
- <?PHP
- $Poizvedba_Mesta = mysql_query("SELECT * FROM Mesta WHERE Id_Regije = '$Regija' ORDER BY Id");
- while ($Izpis_Mest = mysql_fetch_assoc($Poizvedba_Mesta))
- {
- ?>
- <option value="<?PHP echo $Izpis_Mest['Id'] ?>" <?PHP if ($Mesto == $Izpis_Mest['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Mest['Ime'] ?></option>
- <?PHP
- }
- ?>
- </select>
- </fieldset>
- </form>
- <?PHP
- }