Click to See Complete Forum and Search --> : Connecting to a database using javascript


Gerom7
06-09-2006, 03:25 PM
Is it anyway possible to connect to a database using java script. Solution that i am using right now is one that found www.w3schoo.com/ado. However my entire page is written in Java. I would be able to implement this vb/asp code on a web page. However I will neet to convert data in table from vb script to javascript.
Question is can you connect to a database using Javascript? And if not how to convert entire table that was read in vbscript to javascript.

Any suggestions is very much welcomed and appreciated.

Thank You very much.

Igor :eek:

lmf232s
06-09-2006, 04:00 PM
No you cant connect to the database using javascript.

Depending on what your trying to do, all you need to do is connect to the
database, read the results and then pass those results to a javascript function or
set a javascript variable = to the results.


<%
sSQL = "SELECT * FROM TABLE"
set oRS1 = oConn.Execute(sSQL)
Do While Not oRS1.EOF
sResults = sResults & oRS1("FIELDNAME")
oRS1.MoveNext
Loop
%>

<script langauge=javascript>
var TableResults = <%=sResults%>;
</script>

Gerom7
06-09-2006, 04:14 PM
I will try this.

Thank You very much.

Gerom7
06-12-2006, 09:05 AM
The obstical is that I want to connect to a database depending on the value(table) that is user is going to select. For example the user is going to select table "books" then the vaule "Books" will be passed to the function and script will assign it to SQL statement. However, I can connect to DB only using VBscript but client side scripting must be done in JavaScript. There is of course a huge problem rises,! what script should I use to call function that connects to database,? (function must accept parameters), depending on what user is going to select and then reasigning that whole junk of data back to javascript variable and write it to the page. But that is very cumbersom. Is it other any simple way around this.

Thank You very much.

Igor