Possible Duplicate:
How to connect to SQL server database from javascript?
How can I run sql query inside javascript function? Hope you can help. many thanks.
Possible Duplicate:
How to connect to SQL server database from javascript?
How can I run sql query inside javascript function? Hope you can help. many thanks.
Unless you are using something like node.js, the javascript code is executed on the client side (in the user's browser), so it doesn't have access to the SQL server.
You should do the SQL query on the server side (e.g. in PHP or the language you use on the server side), and do Ajax requests on the client side.
Short answer is, you can't. But you can use ajax to fire a request to the server, which runs the query and returns the results.
JavaScript is client side, SQL is server side. Probably you just have to write a server script, like in PHP, that return sql results and with javascript and AJAX technology get that results and work on it with javascript on client side. Learn about AJAX and ie. jQuery.