To elaborate on zorgi's answer, Ajax is probably what you're looking for.
If you're unfamiliar, please read about it here:
http://www.w3schools.com/Ajax/ajax_intro.asp
Ajax is actually built on JavaScript and it gives one the ability to retrieve data through a GET or POST request without refreshing a page.
Your current configuration reloads the page while passing some GET data. This is repeated each time the target drop-down menu item is changed and this event is triggered through an event handler. The specified PHP script parses the GET data and retrieves information accordingly. From there, the script must redirect the user to another page for displaying output or dump results from the script itself.
Your method is on the brink of simulating an Ajax request.
Your question, "
how can I access the values," is a little unclear. If you wish to access them, you can use PHP to output HTML along with your values by looping through the $table array or by specifying any of the $table elements individually. I assume that you already know that, so your question might be, then, "
how can I access the values in JavaScript?"
Well, after you've read the article referenced above about Ajax, you will have learned that your PHP script's output data is returned to your page and stored in the
req.responseText property. The process might look something like this:
In PHP, if you execute this code:
You get an output that looks like this:
So, the data returned to your page from the Ajax request is actually a string value. If you were to execute this code in your javascript
:
Then you would get a dialog box that says, "Array." This is obviously not what we want. What we must do, then, is not simply use the PRINT command in PHP, but rather dump the data in a format that can be parsed by JavaScript.
For example, if your $table array looked like this:
- <?php
-
$table = array( 'key' => 'value' , 'anotherKey' => 'anotherValue' );
-
?>
Then you could output the data like this:
- <?php
-
foreach($table as $key=>$val) {
-
echo "$key=$val\n";
-
}
-
?>
Which will produce the following output:
- key=value
-
anotherKey=anotherValue
This data will then be returned to your page and is accessed through the req.responseText property. You will have to write some JavaScript code to parse this data.
From here you're on your own. I hope this helps, but please ask if you have more questions!