Slighty improve javascript.

- use only one call of sql_select
- use only one call of sql_format
- use jQuery selector instead of getElementById to avoid js errors when
not found.
Merge pull request #183 from rjuju/fix_js

Slighty improve javascript.