Hi.
How php can wait for a select variable?
I need to have user select data before php continues.
I'm selecting unique id of a cities with the same namein the country.
Here is the code, a mix of code and pseuodocode, or whatever.
Somebody can help me?.
Thanks in advance.
Peter.
<?php
require ("some_functions.php");
..........
..........
Input statements....
.........
........
$city = "Cool City";
$city_ok = search_city($city); // Here calls a function.
if (!$city_ok):
echo "$city not found<BR>\n";
exit;
endif;
Continue normal processing with founded city.
........
.......
?>
Contents of "some_functions.php"
<?php
function search_city($city) {
mysql statements...
Returns 4 cities with the same name, (Cool City)
stored in arrays $city_name[], $city_location[], $city_id[],
and the array cardinality in $num_cities.
So:
switch ($num_cities) {
case 0:
$city_found = false;
break;
case 1:
$city_found = $city_id[0];
break;
default: // More than 1 city.
$city_found = select_a_city($city_name, $city_location, $city_id);
}
return $city_found;
}
function select_a_city($city,$location,$id) {
Here I build de <select> and so on,
echo "<FORM NAME = \"form\">";
echo "<P><SELECT NAME = \"the_result\" onchange=\"giveme_id()\">";
$num_ids = count($id);
for ($i = 0; $i < $num_ids; $i++) {
echo "<OPTION VALUE=\".$id[$i]."\">".$city[$i].$location[$i];
}
echo "<OPTION VALUE=\"0\">None";
echo "</SELECT></P>";
echo "<P><INPUT TYPE=\"hidden\" VALUE=\"city_selected\" NAME=\"city_selected\"></P>";
echo "<P><INPUT TYPE=\"submit\" VALUE=\"Submit\" NAME=\"submit\"></P>";
echo "</FORM>";
!!!!!! Here is the trouble, the program dont't wait to choose a
city, so always $city_selected is false (no value).
Of course, if we choose a city after that, the javascripts function returns
the correct value, but there is no variable waiting for it.
How can I get the value from the select, while the program is waiting?
return $city_selected;
}
?>
<SCRIPT LANGUAGE="Javascript">
function giveme_id()
document.form.city_selected.value = document.form.the_result.value;
}
</SCRIPT>