For this to work, you need to use AJAX. This can be done using just plain old javascript or your favorite library. Using a library would be much easier. I tend to use YUI myself.
What you need to do is quite simple:
- Listen to project selection box for changes.
- When a change happens, send a request using AJAX to your PHP endpoint.
- Your endpoint then returns a JSON response containing the values of the task selection box.
- Use javascript to decode the JSON response and create
<option>
elements for your task selection box.
A quick example:
PHP side:
<?php
$list = array('list' => array('task1' => 1, 'task2' => 2));
header('Content-Type: application/json; charset=utf-8');
echo json_encode($list);
exit();
JS side (I am using YUI, and this is for the AJAX only, you will still need to write code to listen for the selection box changing):
<script>
// Create a YUI instance using io-base module.
YUI().use("io-base", function(Y) {
var uri = "get.php?foo=bar";
// Define a function to handle the response data.
function complete(id, o) {
var data = Y.JSON.parse(o.responseText);
//Parse the JSON, loop and insert the options here.
};
// Subscribe to event "io:complete"
Y.on('io:complete', complete);
// Make the request
Y.io('http://mysite.com/myendpoint.php');
});
<script>