What I want to achieve is to create two drop-down menus, but where the options listed in the second list are dependent on what the user selects from the first.
Simple example - let's say the first drop down list asks what country you live in. Depending on which country is selected, the second box should display a list of states (or provinces/countries/regions etc) pertinent to that country.
Obviously I'm looking for a cross-browser compatible solution. Javascript? I'm not sure... Should I use some Javascript that refreshes the page and send the countryid to that same page?
Or should I look for an effective dynamic client-side solution so that the browser does not have to refresh when the first selection is made in order to display the second list?
By the way, I'm using MySQL and PHP for the server-side and I know NOTHING of Javascript, so I would need the whole script, here's what I have so far:
<?php
mysql_connect("localhost","","");
mysql_select_db("abctango");
if (!isset($pais)) $pais=11;
/ 11 is my country's id, this way that one is the default country in the list /
$sql="select * from paises order by 2";
$res=mysql_query($sql);
while($fila=mysql_fetch_array($res))
{
print("<option value=\"$fila[id_pais]\"");
if ($fila[id_pais] == $pais) {
print ("selected");
$divi=$fila[id_div];
}
print(">$fila[pais]</option>");
}
print(" </td>
</tr>
<tr>
</select>
<td><select name=\"prov\">
");
$sqlprov="select * from provincias where id_pais='$pais' order by 2";
$resprov=mysql_query($sqlprov);
while($filaprov=mysql_fetch_array($resprov))
{
print("<option value=\"$filaprov[id_prov]\"");
if ($filaprov[id_prov]==26) {
print ("selected");
}
print(">$filaprov[prov]</option>");
}
print("</select> ");
?>
Thank you very much!!!