Reply
read ms access database, store value in javascript variable
Old 05-15-2005, 11:16 PM read ms access database, store value in javascript variable
Junior Talker

Posts: 2
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 07:18 PM.
Niko2005 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-16-2005, 01:57 AM
chrishirst's Avatar
Super Moderator

Posts: 13,626
Location: Blackpool. UK
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!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to read ms access database, store value in javascript variable
 

Thread Tools

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

vB 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.12562 seconds with 12 queries