Estou precisando que quando o usuário selecionar um item combo que o próximo combo seja carregado com os dados relacionados a ao primeiro.
Já fiz isso:
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>PHP form select box example</title>
</head>
<body>
<?php
$selected='';
function get_options($select)
{
$countries=array ('United States'=>1,'United Kingdom'=>2,'France'=>3,'Mexico'=>4,'Russia'=>5,'Japan'=>6);
$options='';
while(list($k,$v)=each($countries))
{
if($select==$v)
{
$options.='<option value="'.$v.'" selected>'.$k.'</option>';
}
else
{
$options.='<option value="'.$v.'">'.$k.'</option>';
}
}
return $options;
}
if(isset($_POST['countries']))
{
$selected= $_POST['countries'];
$_SESSION['pais'] = $selected;
}
function get_cidade()
{
if(isset($_SESSION['pais'])){
$pais = $_SESSION['pais'];
$options2='';
if($pais==1)
{
$options2.="<option value='New York' selected>New York</option>\n";
$options2.="<option value='San Francisco'>San Franciso</option>\n";
$options2.="<option value='Washington'>Washington</option>\n";
}
if($pais==2)
{
$options2.="<option value='London'>London</option>";
$options2.="<option value='Manchester'>Manchester</option>";
$options2.="<option value='Edimburgo'>Edimburgo</option>";
}
if($pais==3)
{
$options2.="<option value='Paris'>Paris</option>";
$options2.="<option value='Lyon'>Lyon</option>";
$options2.="<option value='Marselha'>Marselha</option>";
}
if($pais==4)
{
$options2.="<option value='Cuidad del Mexico'>Cuidad del Mexico</option>";
$options2.="<option value='Guadalajara'>Guadalajara</option>";
$options2.="<option value='Monterrei'>Monterrei</option>";
}
if($pais==5)
{
$options2.="<option value='Moscou'>Moscou</option>";
$options2.="<option value='Samara'>Samara</option>";
$options2.="<option value='Kaluga'>Kaluga</option>";
}
if($pais==6)
{
$options2.="<option value='Toquio'>Toquio</option>";
$options2.="<option value='Quioto'>Quioto</option>";
$options2.="<option value='Hiroshima'>Hiroshima</option>";
}
return $options2;
}
}
?>
<form name="frm1" action="testetabelas7.php" method="post">
<form name="fcountries" id="frm2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for='formCountries[]'>Select the countries that you have visited:</label><br>
<select name="countries" onchange="form.submit();" >
<?php echo get_options($selected); ?>
</select><br>
</form>
<p>Cidade</p>
<form name="cities" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="cidade">
<?php echo get_cidade(); ?>
</select>
</form>
<input form="frm1" type="submit" value="Gravar" >
</form>
</body>
</html>
O problema está que quando mudo a opção o submit não está sendo para o submit do form interno, mas para o form externo.
Já tentei this.form.submit()
Eu não sei como chamar dar submit no form interno.
O arquivo testetabelas7.php:
<!DOCTYPE HTML>
<html>
<head>
<title>PHP form select box example</title>
</head>
<body>
<?php
$co = $_POST['countries'];
$cy = $_POST['cidade'];
echo '<p>'.$co.'</p>';
echo '<p>'.$cy.'</p>';
?>
</body>
</html>