Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-28-2005, 11:11 PM   #1 (permalink)
awieds
Registered User
 
Join Date: Mar 2005
Posts: 42
awieds is on a distinguished road
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!
awieds is offline   Reply With Quote
Old 06-28-2005, 11:52 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 661
DJMaze is on a distinguished road
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
DJMaze is offline   Reply With Quote
Old 06-28-2005, 11:54 PM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-28-2005, 11:59 PM   #4 (permalink)
awieds
Registered User
 
Join Date: Mar 2005
Posts: 42
awieds is on a distinguished road
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
awieds is offline   Reply With Quote
Old 06-29-2005, 12:35 AM   #5 (permalink)
awieds
Registered User
 
Join Date: Mar 2005
Posts: 42
awieds is on a distinguished road
How do I create javascript holding infofetched from database using vbscript?
Thanks!
awieds is offline   Reply With Quote
Old 06-29-2005, 12:54 AM   #6 (permalink)
awieds
Registered User
 
Join Date: Mar 2005
Posts: 42
awieds is on a distinguished road
I created the array in vbscript but my javascript code doesn't recognize it. How can I get it to recognize it?
Thanks
awieds is offline   Reply With Quote
Old 06-29-2005, 03:55 AM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 661
DJMaze is on a distinguished road
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?
DJMaze is offline   Reply With Quote
Old 06-29-2005, 11:05 PM   #8 (permalink)
awieds
Registered User
 
Join Date: Mar 2005
Posts: 42
awieds is on a distinguished road
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!
awieds is offline   Reply With Quote
Old 06-30-2005, 01:26 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
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>
...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to Access Database awieds MS Technologies ( ASP, VB, C#, .NET ) 4 04-09-2005 11:27 PM
Can't see MySql database records in Mozilla monicao PHP 3 05-02-2004 05:19 PM
mysqladmin: connect to server at 'localhost' failed infinite_root PHP 3 04-30-2004 06:50 AM
Methods of moving a database... DarkTwilkitri PHP 8 11-19-2003 05:02 AM


All times are GMT -8. The time now is 09:27 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting