I have a webpage where I have a form with several areas to input text and two drop down select options countries is the first one and depending in witch country is chosen the second should display the estates for that country to choose. my page connects to my db from where it gets the countries and estates.... I have a table with the country names and one table for each country estates. so all I'm trying to do is making it change the states to choose from automatically depending witch country got selected with out summiting the form since that enters a new entry to another table in my db. I seen that using javascript is the way to go but can't get it to work in my case since I don't want to be sent to another page or summit the form. here is part of my code any help will be greatly appreciated. Thanks
$paissql = "SELECT * FROM Paises_table";
$paisresult = mysql_query($paissql);
?>
<script language="text/javascript">
function showMe(str)
{
<? $estadosql = "SELECT * FROM ".str."_table";
$estadoresult = mysql_query($estadosql); ?>
}
</script>
<TABLE BORDER="2" CELLPADDING="2" CELLSPACING="2" ALIGN="CENTER">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method=POST>
<TR><th> id </th> <td><?php echo $row_to_edit['id']?></td>
</TR>
<TR><th>Nombre:</th><td><input type="TEXT" name=Nombre value="<?php echo $row_to_edit['Id_Nombre']?>"
SIZE="100"></td></TR>
</td></TR>
<TR><th>Pais:</th><td>
<select name=Pais onchange="showMe(this.value);" >
<?
while($rowp = mysql_fetch_array($paisresult)) {
$pais = $rowp['Name'];
?>
<option value=<?php echo $pais; ?>
<?php if($row_to_edit['Pais']==$pais)
{ echo ' selected="true"';} ?>
><?php echo $pais; ?>
</option>
<?
}
?>
</select></td></TR>
<TR><th>Estado:</th><td>
<select name=Estado >
<?
while($rowe = mysql_fetch_array($estadoresult)) {
$estado = $rowe['Estado'];
?>
<option value=<?php echo $estado; ?> <?php if($row_to_edit['Estado']==$estado)
{ echo ' selected="true"';} ?>
><?php echo $estado; ?></option>
<?
}
?>
<TR><th>Ciudad:</th><td><input type="TEXT" name=Ciudad value="<?php echo $row_to_edit['Ciudad']?>"
SIZE="100"></td></TR>
<TR><th>Website:</th><td><input type="TEXT" name=website value="<?php echo $row_to_edit['website']?>"
SIZE="100"></td></TR>
<TR><td> </td>
<td>
<input type="HIDDEN" name="id" value="<?php echo $edit_id?>">
Para agregar preciona aqui:
<input type="SUBMIT" name="ACTION" value="AGREGAR">
</td>
</TR>
</form>
</TABLE>
<BR>
<BR>