Is it possible to execute the query in javascript.
No. Not possible. Query can only run on server.
Thus, if you want to run a query on server you need to talk to server via Javascript.
There are few ways to interact with server side through client side(Javascript):
1.
XMLHttpRequest[
^]
2.
Callback[
^]
3.
WebService call[
^]
4.
PageMethod[
^]
Pick the one that suits you.