DoofuS
asked on
Javascript + HTML + Access database. Is it possible to coexist without a web server?
Helllo experts,
I would like to know if it is possible to retrieve/update a MS Access database by using Javascript, HTML only without having to have a web server. I have a snippet of code and would like to know if it is correct. thanks!
I would like to know if it is possible to retrieve/update a MS Access database by using Javascript, HTML only without having to have a web server. I have a snippet of code and would like to know if it is correct. thanks!
<html>
<head>
<title>Populate Dropdown Using JScript</title>
<script language="text/Jscript">
function loadData()
{
var appPath;
var cn;
var rs;
var sql;
var conn;
try {
rs = new ActiveXObject("ADODB.Recordset");
}
catch (e) {
alert("ADODB namespace not found.");
exit(0);
}
appPath = "c:\QTPDb.accdb"
conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + appPath + ";Persist Security Info=False";
var sql = "select ColA from TableA";
rs.Open(sql, cn);
rs.open(sql, conn,0, 1, 1);
rs.movefirst();
while (rs.eof != true) {
var optn = document.createElement("OPTION");
optn.text = rs("ColA");
optn.value = value;
document.mylist.options.add(optn);
}
rs.Close();
}
</script>
</head>
<body onload=loadData()>
<SELECT name="mylist">
</SELECT>
</body>
</html>
ASKER
Thanks. I will make that change and run it...my earlier run with the original code resulted in an error.
ASKER
I have modified a bit per your suggestion, I still can't get this working. I have this named as Test.html and it is stored in the same directory as the access db. Any ideas?
<html>
<head>
<title>Populate Dropdown Using JScript</title>
<script type="text/javascript">
function loadData()
{
var appPath;
var conn;
var conn_str;
var rs;
var sql;
conn_str= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\QTPDb.accdb;Persist Security Info=False;";
conn = new ActiveXObject("ADODB.Connection");
alert("Before Connexn Setup");
conn.open(conn_str)
alert("After Connexn Setup");
rs = new ActiveXObject("ADODB.Recordset");
sql = "select CauseOfLoss1 from IMContEquip1";
rs.Open(sql, conn );
rs.movefirst();
while (rs.eof != true) {
var optn = document.createElement("OPTION");
optn.text = rs(0);
optn.value = value;
document.mylist.options.add(optn);
}
rs.Close();
}
</script>
</head>
<body>
<form name="frm" method="post">
<table>
<TR>
<TD><INPUT name="btnSubmit" TYPE="Submit" VALUE="Submit" onclick = "return loadData()"></TD>
</TR>
</table>
</form>
<SELECT name="mylist">
</SELECT>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just to test...
Change this line to your SQL:
rs.open ("select ID from tbl_log", conn);
And this line to new Access connection string and database path::
val = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" + "C:/finance/../myDB.mdb" + ";Persist Security Info=False";
Change this line to your SQL:
rs.open ("select ID from tbl_log", conn);
And this line to new Access connection string and database path::
val = "Provider=Microsoft.Jet.OL
ASKER
I have a Ms access 2007 database. Would that affect anything in the connection string?
Yes, sorry. I was only able to test in 2003. Just change the connection string (like you did before). It's different for 2007.
Provider=Microsoft.ACE.OLE DB.12.0;Da ta Source=C:\myFolder\myAcces s2007file. accdb;Pers ist Security Info=False;
Provider=Microsoft.ACE.OLE
Here's what it should look like:
conn = "Provider=Microsoft.ACE.OL EDB.12.0;D ata Source=" + appPath + ";Persist Security Info=False;";
conn = "Provider=Microsoft.ACE.OL
ASKER
Cool...I have changed the connection string to this:
conn_str= "Provider=Microsoft.ACE.OL EDB.12.0;D ata Source=c:\QTPDb.accdb;Pers ist Security Info=False;";
Thanks a million :)!!!
conn_str= "Provider=Microsoft.ACE.OL
Thanks a million :)!!!
ASKER
Awesome solution!
Access 2007 Connection string:
Provider=Microsoft.ACE.OLE
Connection Code:
var conn = new ActiveXObject("ADODB.Conne