You'll need to consider several things.
1. How you'll be sending the chosen value to the PHP script.
2. How your PHP page will be returning the values it gets from the database.
For the first one its either POST or GET are your choices. GET being the simpler one as you can just attach the value to the URL of the PHP script when you call it.
Code:
var myreq=new XMLHttpRequest();
myreq.open("GET","popdrop.php?myvalue=" + dropdwn.value,false);
myreq.send();
var results=myreq.responseText;
The XMLHttpRequest object is what allow the connection to a PHP script to retrieve the output of the script.
For Part 2
I would have my PHP script built to return either a Json array that my JS code can use to construct the new drop down, or simply return a string that you can split and manipulate lter.
An example of the string method follows:
Code:
$conn=mysql_connect(...) or die(mysql_error());
$db=mysql_select_db(...) or die(mysql_error());
[green]Assuming the request was done using the GET method, ou would want to search for the value from the dropdown in GET super global. [/green]
$id=mysql_real_escape_string($_GET['cntry']); [green]Alwasy good to cleanse any variables[/green]
$qry="SELECT *FROM states WHERE Country_ID=$id";
[green]Build the query using the obtained value.[/green]
$res=mysql_query($qry);
$options="";
while($row=mysql_fetch_array($res)){
$options.=$row['id'] . "," . $row['name'] . "\n\r";
[green]Construct the string o Json array that wil be returned to the JS script[/green]
}
echo $options;
[green]Output, so the response cna be read by the Javascript code.[/green]
?>
Then its just a matter of manipulating the string or json array received in the JS part to build the dropdown.
----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
Behind the Web, Tips and Tricks for Web Development.