Page 1 of 1

dropdown problem

Posted: Wed Aug 04, 2004 6:00 am
by Think Pink
hello. I have the following script (the short version just to make you an ideea). Is a form that inputs data into a table when "submit" is pressed.

when dropdown "selTara" changes the dropdown "selJudet" is loaded with cityes that belong to the appropriate state selected in "selTara".
Example : If i choose France in dropdown 1, in dropdown 2 will appear Paris, Lyon, etc.

So far so good.
What i need is for dropdown 1 to keep the id I choosed. In my script, reloads to the default.

Pls Help.

Here is the script:

Code: Select all

<?php
<?
include("connect_to_db.php"); 
?>
<table align="center" width="100" cellspacing="0" cellpadding="0" border="1">
<form name="myform" action="test8_1.php" method="post">
<tr>
<td align="center" valign="middle">
<select name="selcountry" onchange="document.forms[0].action='<? $PHP_SELF; ?>'; document.forms[0].submit()">
<option selected value="0">Select country <?php
$sql = "SELECT id_country, country_name FROM country ORDER BY country_name ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_country']."'>".$row['country_name']."</option>";
}
?>
</select>

</td>
<td align="center" valign="middle">
<select name="selJudet"> 
<option selected value="0">Select city
<?php 
$sql = "SELECT id_location, location_name FROM location WHERE id_country='".$_POST['selcountry']."'";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_location']."'>".$row['location_name']."</option>";
}
?>
</select>
</td>
</tr>

<td align="center" valign="middle"><input type="text" name="something"></td>
</tr>


<input type="submit" name="addToTabel">

</form>
</table> 
?>

Posted: Wed Aug 04, 2004 6:13 am
by feyd
you need to write "selected" into the option they selected.. we've had many many discussions on this, one quite recently...