Once the PHP script has run it sends the output to the client machine. So you can't call the function when the client clicks unless you use an AJAX call to another file.
So you need to move the function to it's own file. Maybe:
get-select-options.php
Put your function in there and then the call to that function at the top as an echo:
<?php
echo dropdown_tag_cloud('number=0&order=asc');
function tag_cloud($parameters){
return $stuff;
}
?>
In your main file you can create a ajax call to get the results. Use JQuery
<script>
$('select[name=tag-dropdown]').click(function(){
$.get('select-options.php', {}, function(r){
$('select[name=tag-dropdown]').append(r);
});
});
</script>
I would add in a loading animation so the user knows to wait.
If you need to pass parameters to the function you can do so inside the ajax call:
$.get('select-options.php', {'number':3, 'order':'asc'}, function(r){});
and then in the PHP file you can use $_GET to retrieve the paramters
$number = $_GET['number'];
$order = $_GET['order'];
EDIT:
You could also populate a variable in JS with the PHP output on the same page and then update the select options on click.
Important The output of the "dropdown-tag-cloud" function must be a string for the way I have it written to work: (example: <option value="asdf">tag</option><option value="qwer">tag</option>)
<script>
var options = '<?php echo dropdown_tag_cloud(0,"asc")'; ?>;
$('select[name=tag-dropdown]').click(function(){
$('select[name=tag-dropdown]').append(options);
});
</script>