Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 3rd, 2010, 06:50 PM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connect to Access 2007 with JavaScript

I am trying to create a JavaScript that will take the inputs of a Web form, generate a query from those inputs, query a database, and display the results of the query on the page. Right now I just want to create a script that will run a hard-coded query and display the results when I push a Submit button. The database is an Access 2007 file (.accdb) that is stored on the server where I am building the page.

Here is my page so far:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>School of CIS TCPT</title>

<script language="JavaScript" > 

function getSubmit() 
{ 
var ClassID;
var CreditHours;

var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = classes.accdb;Persist Security Info=False"; 
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "SELECT 0910.ClassID, 0910.CreditHours FROM 0910"; 
var resultSet = strConn.query(SQL);
cn.Open(strConn); 
rs.Open(SQL, cn); 
ClassID.value = rs(0); 
CreditHours.value = rs(1);
rs.Close(); 
cn.Close(); 

} 

</script> 

<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style2 {color: #c80000}
-->
</style>
</head>

<body>

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="bodystyle">
  <tr>
    <td class="header"><p align="center">School of Computer and Information Sciences Advising System <span 

class="style2">Transfer Course Plan Tool</span></p>    </td>
  </tr>
  <tr>
    <td height="10">&nbsp;</td>
  </tr>
  <tr>
    <td>Use the form below to enter your information and preferences, then click &quot;Submit&quot; to 

generate a course plan. Fields with an asterisk are required.</td>
  </tr>
  <tr>
    <td height="10">&nbsp;</td>
  </tr>
  <tr>
    <td><table width="615" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="35" colspan="2">* Bulletin: &nbsp;
         <select name="bulletin" id="bulletin" tabindex="1">
           <option selected="selected" disabled="disabled">Select Bulletin Year</option>
           <option value="0910">2009-2010</option>
         <option value="1011" disabled="disabled">2010-2011</option>
         </select>          </td>
        <td width="340" height="35">* Starting Semester: &nbsp;
          <select name="semester" id="semester" tabindex="2">
            <option selected="selected" disabled="disabled">Select Semester</option>
            <option value="fall">Fall</option>
            <option value="spring">Spring</option>
          </select></td>
      </tr>
      <tr>
        <td height="35" colspan="2">* Major: &nbsp;
          <label>
          <select name="major" id="major" tabindex="3">
            <option selected="selected" disabled="disabled">Select Major</option>
            <option value="cs" disabled="disabled">Computer Science</option>
            <option value="is" disabled="disabled">Information Science</option>
            <option value="it">Information Technology</option>
          </select>
          </label></td>
        <td height="35">* Select Concentration: &nbsp;
          <label>
          <select name="concentration" id="concentration" tabindex="4">
            <option selected="selected" disabled="disabled">Select Concentration</option>
            <option value="data" disabled="disabled">Data Management</option>
            <option value="web">Web Publishing</option>
            <option value="networking" disabled="disabled">Networking</option>
            <option value="forensics" disabled="disabled">Digital Forensics</option>
          </select>
          </label></td>
      </tr>
      <tr>
        <td width="150" height="35">* Are you Calculus ready?          </td>
        <td width="125" height="35"><form id="form1" name="form1" method="post" action="">
            <label>
              <input type="radio" name="radio" id="calcready" value="yes" tabindex="5" />Yes              

</label> &nbsp;<label>
              <input type="radio" name="radio" id="calcready" value="no" tabindex="6" />No
              </label>
          </form></td>
        <td height="35">Preferred Hours per Semester: &nbsp;
          <label>
          <select name="hours" id="hours" tabindex="7">
            <option selected="selected" disabled="disabled">Select Hours</option>
            <option value="parttime">&gt;12 (Part Time)</option>
            <option value="regfulltime">12 - 15 (Full Time)</option>
            <option value="extrafulltime">16+ (Full Time)</option>
          </select>
          </label></td>
      </tr>
      <tr>
        <td height="35" colspan="3"><div align="center">
          <input type="reset" name="reset" id="reset" value="Reset" accesskey="R" tabindex="9" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <label>
        <input type="button" value="Submit" accesskey="S" tabindex="10" onclick="getSubmit()" />
        </label>
        </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

</body>

</html>
I tried getting a pop-up message box to display the results, but when I clicked "Submit," nothing happened.

Then I tried "alert("test");" on the Submit button and still nothing happened. So I tried putting a "document.write("Hello World!");" into the page to see if JavaScript itself was even working, and the Hello World script DID WORK. So obviously, something is wrong with my getSubmit() function.

Help? Ideas? How do I make this work?
Reply With Quote
  #2 (permalink)  
Old April 4th, 2010, 03:19 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your page has three main problems, firstly it will only work if it's run from a browser that's on the server wherer the database exists, secondly the page would have to be in the same folder as the database and lastly security permissions would have to be very low as to allow access to the database file.

Is it your intention to only run this page from the web server locally? It's a strange scenario.
__________________
Joe
http://joe.fawcett.name/
Reply With Quote
  #3 (permalink)  
Old April 4th, 2010, 09:04 AM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The page and the database are in the same folder.

The scenario I am trying to create is a Web-based app where students at my school can input a few bits of information about themselves (current bulletin year, major, concentration, etc.) and have a sample course plan (what classes to take in which semester for the next 4 years) generated for them. The database doesn't need to be blocked from anyone's view, because it only contains information which is already published in the University's bulletin in print and online. It is not sensitive information.
Reply With Quote
  #4 (permalink)  
Old April 4th, 2010, 12:37 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Fine, then you will need to use server-side coding that runs on the server where the database resides, not client-side which runs in the browser on the machine that requests the page. If you want to go the Microsoft route then ASP.NET is probably best, otherwise Jave or PHP.
__________________
Joe
http://joe.fawcett.name/
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to specify relative path to Access 2007 in ADO connection string? [Excel 2007] sektor Excel VBA 4 September 3rd, 2009 11:59 PM
Sending email in access 2007 maxgrunt BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 1 July 31st, 2008 09:21 PM
Access 2007 JohnBoy VB.NET 2002/2003 Basics 1 March 16th, 2008 09:33 PM
Access 2007 Ribbons? bgnetman Access VBA 2 October 30th, 2007 11:03 AM
Access 2007 - wtf? mmcdonal Access 7 December 19th, 2006 07:45 AM



All times are GMT -4. The time now is 01:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.