|  | |  |
06-29-2005, 12:11 AM
|
#1 (permalink)
| | Registered User
Join Date: Mar 2005
Posts: 42
| Connect to Database How do I connect to a database using Javascript? I have an asp page. I connect to the database using VBscript and it works fine but I don't know how to connect using javascript.
The following is my vbscript code:
Set rs = Server.CreateObject("ADODB.Recordset")
strQuery="Select * from products"
rs.Open strQuery, MM_myConn_STRING, 0, 2 ,1
How do I do that in javascript??
Either that or I can create an array using vbscript if there is a way for me to access it in javascript.
Thanks! |
| |
06-29-2005, 12:52 AM
|
#2 (permalink)
| | Senior Contributor
Join Date: Mar 2005
Posts: 746
| do you know javascript is client side scripting?
anything which is on that side of the globe shouldn't contain any login system so not available |
| |
06-29-2005, 12:54 AM
|
#3 (permalink)
| | Newbie
Join Date: Jun 2002 Location: Denmark
Posts: 1,726
| Quote: |
How do I do that in javascript??
| You don't
Javascript runs clientside, asp runs serverside.
Do you see the difference ??
The way to go, would be to create your javascript holding the information fetched from the database using your vbscript, so you'd dynamicaly create the javascript from your serverside run asp, which then can be run clientside. |
| |
06-29-2005, 12:59 AM
|
#4 (permalink)
| | Registered User
Join Date: Mar 2005
Posts: 42
| Yes, I understand. I am just stuck!
How do I create the array using vbscript and then access it through javascript??
(Because I need to access an element on the page to match up so I need to do that using javascript)
When I tried creating a recordset with VBscript and then using it with javascript it didn't recognize the recordset |
| |
06-29-2005, 01:35 AM
|
#5 (permalink)
| | Registered User
Join Date: Mar 2005
Posts: 42
| How do I create javascript holding infofetched from database using vbscript?
Thanks! |
| |
06-29-2005, 01:54 AM
|
#6 (permalink)
| | Registered User
Join Date: Mar 2005
Posts: 42
| I created the array in vbscript but my javascript code doesn't recognize it. How can I get it to recognize it?
Thanks |
| |
06-29-2005, 04:55 AM
|
#7 (permalink)
| | Senior Contributor
Join Date: Mar 2005
Posts: 746
| Code: <script language="JavaScript1.2">
var myarray = new array();
</script> Do you have any code to share with us so that we realy understand what, how and when? |
| |
06-30-2005, 12:05 AM
|
#8 (permalink)
| | Registered User
Join Date: Mar 2005
Posts: 42
| Sorry... Code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--#include file="../Connections/myConn.asp" -->
<%
Dim rs
dim strQuery
dim arrProducts()
dim arrDescription()
dim i
Set rs = Server.CreateObject("ADODB.Recordset")
strQuery="Select * from products"
rs.Open strQuery, MM_myConn_STRING, 0, 2 ,1
while not rs.bof and not rs.eof
redim preserve arrProducts(i)
redim preserve arrDescription(i)
arrProducts(i)=rs("ProductName")
arrDescription(i)=rs("Description")
i=i+1
rs.movenext
wend
rs.Close()
set rs=nothing
%>
<script language="javascript">
<!--
function PopulateDesc(prod)
{
alert(prod);
}
</script>
</head>
<body>
<select name="products" id="products" language="javascript" onChange="PopulateDesc(myForm.products.value)">
<% dim j
for j=lbound(arrProducts) to ubound(arrProducts)%>
<option value="<%=arrProducts(j)%>"><%=arrProducts(j)%> </option>
<%next%>
</select>
</body></html> I am trying to get the product that the user selected. I have an alert in my javascript function to test it. It works fine, I got the product. Then I want to get the decription of that product and populate a textbox with it. I have made two parallel arrays in vbscript but how can I use the arrays in javascript or get the product into vbscript??
Thanks for any help! |
| |
06-30-2005, 02:26 AM
|
#9 (permalink)
| | Newbie
Join Date: Jun 2002 Location: Denmark
Posts: 1,726
| Would somethign like this do ? Code: ...
<script language="javascript">
<!--
var description = new array (
<% dim i
for i=lbound(arrDescription) to ubound(arrDescription)%>
"<%=arrDescription(i)%>",
""
);
function PopulateDesc(prod)
{
document.myForm.description.value=description[0 + prod];
}
// -->
</script>
...
<form name="myForm">
<select name="products" id="products" language="javascript" onChange="PopulateDesc(myForm.products.value)">
<% dim j
for j=lbound(arrProducts) to ubound(arrProducts)%>
<option value="<%=j%>"><%=arrProducts(j)%> </option>
<%next%>
</select>
<input type="text" name="description" value="">
</form>
... |
| | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -8. The time now is 03:48 AM. |
Copyright © 2000-2008, Milano Interactive Web Hosting provided by Portal 360 Web Hosting |  | |