...

View Full Version : Can you use Javascript to carry out SQL query?



mikechandler
07-02-2004, 11:07 AM
Hi,

I'm in the process of customising Dreamweaver MX, and am producing a dialog box using HTML and Javascript. I'm looking for a way to populate a <select> dropdown list with values from a database. Is it possible to use Javascript to establish a database connection and then carry out an SQL query?

If not, is it possible to "attach" a .csv file to the HTML document (say as an <object>) containing the values from the database and then for Javascript to read the contents of this file?

I've seen this all done using ASP.NET with C# or VB, but I need to use Javascript for what i'm doing. And haven't really used much Javascript before so not sure quite what's possible with it...

Any help / info would be much appreciated, cheers,

Mike

jbot
07-02-2004, 11:23 AM
you can use JScript/ADO to create clientside DB connections. but it's Win-IE only.

you could look into Javascript Remote Scripting (JSRS) which calls remote methods in serverside languages. there are several implementations of it, most notably Brent Ashley's. There's also a M$ version, but you'll need IIS for that.

have a look :D

Kor
07-02-2004, 11:24 AM
Well I think so. Try this kinda (never tested with php...)



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function goDB(f,v){
f.method='post';
f.action='database.php'+'?'+v;
alert(f.action)
f.submit()
}
</script>
</head>

<body>
<form>
<select size="1" onchange="goDB(this.form,this.value)">
<option>--select--</option>
<option value="v=value1">one</option>
<option value="v=value2">two</option>
</select>
</form>
</body>
</html>

Kor
07-02-2004, 11:29 AM
Or this: (you have not specified if wanna send data or just call queries from)



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function goDB(v){
location.href='database.php'+'?'+v;
}
</script>
</head>

<body>
<select size="1" onchange="goDB(this.value)">
<option>--select--</option>
<option value="v=value1">one</option>
<option value="v=value2">two</option>
</select>
</body>
</html>

jbot
07-02-2004, 11:30 AM
that's not he was asking, Kor.

he wants to be able access a DB directly, not through form submission. :rolleyes:

the only methods are the one's I've outlined.

Kor
07-02-2004, 11:45 AM
eerr, yes, sorry, I was not attentive. Yes, javascript alone can not dialogue with a databse

mikechandler
07-02-2004, 12:21 PM
cheers for that - will look into using ADO with JScript, sounds like it's just what i'm after!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum