|
I want to read price from a ms access database and store it in a javascript variable to be used for calculations.
Any help appreciated,
Thanks,
Niko
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
%>
--------------
|