Very similar to the solution I came up with, only I did the whole accessing the database right inside the javascript function. Just drop into php, do the magic stuff, then back out of php to finish the js function.
I AM going to go follow that other link to see what that solution is about, though! :-)