Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing an Access database in JavaScript - Classic ASP 1

Status
Not open for further replies.

greenber

Technical User
Jul 6, 2016
3
US
I have a front end written using classic ASP. One of its elements is a select/option drop-down menu using Onchange. As such the user will scroll through a bunch of database records, no problem at all using ASP. When the Onchange fires it causes a function, a *JavaScript* function, in the header to be executed. I have no problem constructing the appropriate SQL statement in the form of
"select * where ID=value"

How do I open the desired database (XYZ.MDB, for example) and execute the constructed SQL upon it, all in JavaScript?

(Oh, the database resides on a remote server, protected by a userID/password)

 
How do I open the desired database (XYZ.MDB, for example) and execute the constructed SQL upon it, all in JavaScript?

You can't.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
You cannot directly access a database server with javascript, simple as that.

Your choices are:
[ul]
[li]round trip to the server and construct a query, display the results[/li]
[li]call an ASP url with AJAX, display the results.[/li]
[/ul]



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
As mentioned in the sql server forum you posted in, the only way to do it is with an AJAX call. So, yes the Chris' answer is definitive, you cannot access a database or any server using pure javascript.
what you have to do is use javascript(I suggest using the JQuery framework), to make an AJAX call. This in turn runs code on the server by way of a POST or GET. From there you return an object back (usually a serialized JSON object, as they are the easiest to work with in my experience)

Although it may seem complicated, I would look at the JQuery site and they have many examples to get you started. Once you do it, you will see it is not very hard to do at all.
Take a look here to get you started:
 
You could also use javascript to submit the form in the ONCHANGE event and handle things that way, but that can be awkward as the page will refresh each time a different option is selected
 
I see now, what I said above is basically the first of ChrisHirst's two suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top