|
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.
|