You can either have all data listed in arrays in javascript, or you can do a background server query upon a selection change.
As for putting the data into a js array, if you have no problem pulling data out of the db and working with it then it's pretty simple really, it's just a matter of looking at how to define an array in js, then creating a variable with a string which contains the js array, and then printing that to the page:
PHP Code:
$jsArray='var myarray=["'.$valueA.'","'.$valueB.'","'.$valueC.'"];';
echo "<script>".$jsArray."</script>";
Hopefully you get the gist with that, I recommend creating a function that takes a regular php array and returns a string with that same array as a js array declaration.
Once you've got that going on it's all about referencing page objects in javascript which is really a topic for the javascript forum.
Bookmarks