I need to when the user selects a combo item that the next combo is loaded with the data related to the first.
I've already done this:
<?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>
The problem is that when I change the option the submit is not being for the submit of the internal form, but for the external form.
I've tried this.form.submit ()
I do not know how to call give submit in internal form.
The testfile7.php file:
<!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>