Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
read ms access database, store value in javascript variable
Old 05-16-2005, 12:16 AM read ms access database, store value in javascript variable
Junior Talker

Posts: 2
Trades: 0
I need to be able to find a record by a unique code from a ms access database,
take the value of the price field in that record,
then store the value in a javascript variable.

These varibles are being used for calculations.

So can I change the hard coded javascript code
e.g.
var price1=(229); // 229 being $229 the price for item1

to
var price1=(item1); // item1 = 229 - value read from database and stored in variable price1.

Thanks.

--------------------------

This is my test code:

<html>
<head>
<title>test</title>
<!-- Read database -->
<!--#include file="include/testg1/HG1DK121I.asp" -->

<script language="javascript">
<!-- store price in javascript variable -->
<!-- this code causes a blank page -->
<!-- leave it out and I get vaiable xxx = 666 -->
var c1D41=( <%= HG1DK121I %> );
<!-- dummy javascript variable -->
var xxx=(666)
</script>

<%
'Reset server objects
HG1DK121I.Close
Set HG1DK121I = Nothing
Set adoConHG1DK121I = Nothing
%>
</head>


<body>

<script language="javascript">
<!-- print dummy javascript variable -->
document.write('vaiable xxx = ' + xxx);
<!-- print database price -->
document.write(c1D41);
</script>

</body>
</html>


----------------

This is the include file HG1DK121I.asp

<%
'Dimension variables
Dim adoConHG1DK121I 'Holds the Database Connection Object
Dim HG1DK121I 'Holds the recordset for the records in the database
Dim strSQLHG1DK121I 'Holds the SQL query to query the database

'Create an ADO connection object
Set adoConHG1DK121I = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoConHG1DK121I.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/Price.mdb")

'Create an ADO recordset object
Set HG1DK121I = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQLHG1DK121I = "SELECT Product.Code, Product.System, Product.Group, Product.Product, Product.Price FROM Product WHERE Code='HG1DK121I'"

'Open the recordset with the SQL query
HG1DK121I.Open strSQLHG1DK121I, adoConHG1DK121I

%>


--------------

Last edited by Niko2005; 05-25-2005 at 08:18 PM..
Niko2005 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-16-2005, 02:57 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Write it on to the page with ASP

HTML Code:
<script type="text/javascript">
var price1=(<%=objRS.fields("price")%>)
</script>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-21-2009, 04:18 PM Re: read ms access database, store value in javascript variable
Junior Talker

Posts: 1
Trades: 0
You are able to connect to Microsoft Access using JavaScript when the HTML file is run locally and the Access .mdb file is accessible to the file system it does not work remotely due to the obvious security issues.

I had a situation where this functionality was actually useful, so I wrote a JavaScript library to simplify the process. This library allows you to execute SQL queries in a single command with the option of selecting the output format of the result-set from choices including JSON, XML, and HTML.

I had a great deal of difficulty finding information or examples of how to connect to Access, so I decided to share my code with the world...

The library is called ACCESSdb and you can get it here!



faulkj is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to read ms access database, store value in javascript variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31888 seconds with 12 queries