View Full Version : database connection
yochan
12-20-2004, 09:58 AM
Hi,
I'm new to Java Script
problem:
I would need to connect to database (.mdb) and retrieve records from the database whenever any event triggered (checkbox/radio button)
Thus, I need to call a function (java script) whenever an event is triggered
however, I have no idea how can I connect to the database in the function.
Can somebody help me? I would really appreciate that
thank you
Johannes
relaxzoolander
12-21-2004, 06:00 PM
javascript?
i think you mean vbscript...using asp web pages.
here is a typical database mdb connection using asp to connect to a database:
[dsn-less connection]
dim myConnect,getSet,myText,database
database="../databasefolder/db.mdb"
Set myConnect=Server.CreateObject("ADODB.Connection")
Set getSet = Server.CreateObject("ADODB.Recordset")
myConnect.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath(database)
myText = "SELECT * FROM tableData"
hope it helps.
dilligaf
12-21-2004, 07:39 PM
Who is this..... (*Pause for effect)... Relaxzoolander?
Yochan, Mr. Zoolander is correct (as it's understood to be his custom) so I'm gonna slide this over to ASP.
yochan
12-22-2004, 06:50 AM
Thank you for the reply
what I meant was java script
I want to have a function (java script) and that function is used to connect to my database. Is that possible?
dilligaf
12-22-2004, 08:29 AM
Maybe look here http://www.tek-tips.com/viewthread.cfm?qid=963909 if it doesn't help maybe Google it.
Honestly I'd not seen JS used as such so it's a new one on me.
Stupid question, why java script?
wyrickj
12-22-2004, 10:36 AM
Yeah same here. I never ever use Javascript to connect to databases. There are security issues and client side JS can't interact with databases.
If you are refering to Jscript (Server-Side Javascript) then yeah it's possible but I still would not recommend it. Use ASP or ASP.NET code to connect to it if possible.
Greyth
12-28-2004, 01:14 PM
You might be able to work something out by using a loop and the response buffer. I've never tried it, and it should work in theory, but I can't say I would actually recomend it.
The problem is that the db connection has to be handled on the server, somehow or another.
Some alternate ways to get the job done might be to make use of a frame or iframe, or depending on the specifics of what you need, you may be able to use Flash to get the info from the server.
Hope that helps..
yochan
12-29-2004, 07:02 AM
Thank you for all suggestions and advice. Those help me alot
Aight, I'm gonna work on it =)
Yochan
Cyber-SEO
12-30-2004, 01:13 AM
There is no way you can use JavaScript to connect to a database.
Here is how you can look at it:
JavaScript = Client Side Script which means it runs things within the browser and it actually runs on the clients machine.
VBScript = Server Side Script which runs on your computer and spits out what ever you want it to spit out to the client.
So having said that, the easiest way to do what you are looking to do is to pre-populate variables into JavaScript if need be and if there are not too many records you are checking you could poor all your info into multiple javascript arrays and then reuse them that way.
Even though I would not suggest doing that :) lol I have actually done it before but the application was used only by me so it was ok. If this is a public application then i suggest refreshing your page every time you need to connect to the db.
My 2 cents ;)
yochan
12-30-2004, 08:54 AM
I have tried several times to connect DB using javascript, and as you said, it did not work. I ended up making arrays in javascript and treated them as records.
I'm wondering if there is a way to pass variables in Javascript and ASP back and forth. If this is not possible, how to pass javascript vars to another page?
thank you guys, you have been very helpfull
Yochan :cool:
Greyth
01-11-2005, 10:14 AM
I don't know if it is the best way, but one way would be to use images...
You can set up an asp page to send binary data and act like a 1x1 pixel clear image that can be called on using an html image tag.
When you want to send a variable back to the server, you can call that image from within your code, passing the variables through the querystring.
From there the asp puts the data into a db, or whatever you want the asp page to do.
The only tricky part is getting the asp page to send back info like it is a gif image, that way the little image can't be displayed thing doesn't show on the screen.
This handles info from client to server, but I don't know how you would go about it in the other direction.
Just from what you've mentioned here, it sounds like you should really look into flash actionscript. It's not a very searchengine friendly way to go, but it sounds liek you are doin something that doesn't need to be anyway.
Using flash, you can very easily send variables back and forth between the client and server. Depending on the type of app you are making, you can even open up a full-on socket connection between the two for even faster data transfer if speed is an issue (like building a chat application or online game). Of course for a socket connection, you will need to use something besides asp for the server, but for just sending and returning variables over http, asp would work fine.
relaxzoolander
01-14-2005, 04:43 PM
asp to javascript---
<%
dim pagename
pagename="butter"
response.write "<script language='javascript'>"
response.write "window.location.href='"&pagename&".html';"
response.write "</script>"
%>
[substitute with any javascript you need to use]
.
relaxzoolander
01-14-2005, 05:00 PM
javascript to asp---
first you must understand that javascript is client-side and asp is server-side.
[as was stated earlier]
so once a page is loaded...communication to asp is no longer active.
...and while a page is being processed by the server....javascript is not active.
so...true 'live' communication does not really occur.
so...communication from javascript to asp will only occur during the change from javascript being active to asp being 'active'.
...this occurs at a new page call.
so...therefore...you can use a simple link to send variables to the asp page.
the link can contain variables that are controlled by javascript...
...like so:
<script type="text/javascript">
var mycolor="blue"
document.write("<a href='somepage.asp?col="+mycolor+"'>click here for the blue page.</a>")
</script>
[please note the use or single['] and double["] quotes.]
.
nkernick
01-29-2005, 08:56 AM
If it helps, I once used a menu system which used javascript to call an IFRAME page, this IFRAME page ran an ASP script which contacted database and then sent the data back to the MAIN page using Java script to alter the DIV id's and the text within them... It was a cool function but had to use IFRAME. which was 1px x 1px.....
vBulletin v3.0.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.