473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HTML Database access using Javascript

Trying to create an HTML page called Project.html that will ask the user for basic information (name, e-mail address, and comments), and when the SUBMIT buttom is hit, add the users to an Access 2007 Database. Ideally, the information would only be able to be added once, but I need the adding sequence to work first. Any and all comments or questions would be appreciated.

Anthony
Beginning Programmer

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <title>Project input Form</title>
  6.     <style type="text/css">
  7.         .style1
  8.         {
  9.             width: 70%;
  10.         }
  11.         .style2
  12.         {
  13.             text-align: right;
  14.             width: 261px;
  15.         }
  16.         #Text1
  17.         {
  18.             width: 191px;
  19.         }
  20.         #Text2
  21.         {
  22.             width: 189px;
  23.         }
  24.         #Text3
  25.         {
  26.             width: 190px;
  27.         }
  28.         #Button1
  29.         {}
  30.     </style>
  31.     <SCRIPT LANGUAGE="JavaScript">
  32.     function addrecord (form) {
  33.         var cn = new ActiveXObject("ADODB.Connection");
  34.         var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\aknab\My Documents\testingapp\users.accdb;Persist Security Info=False";
  35.         cn.Open(strConn);
  36.         var rs = new ActiveXObject("ADODB.Recordset");
  37.         var SQL = "select count(*) from Customers";
  38.         rs.Open(SQL, cn);
  39.         alert(rs(0));
  40.         rs.AddNew 'Prepare the database to add a new record and add
  41.         rs.Fields("name") = Request.Form("cname");
  42.         rs.Fields("email") = Request.Form("cemail");
  43.         rs.Fields("comments") = Request.Form("ccomments");
  44.  
  45.         rs.Update;   'Save the update
  46.  
  47.         rs.Close();
  48.         cn.Close();  
  49.     }
  50.     </script>
  51. </head>
  52. <body>
  53.  
  54.     <p style="text-align: center">
  55.         Vetsulin Test page.<br />
  56.     </p>
  57.     <table class="style1">
  58.         <tr>
  59.             <td class="style2">
  60.                 Name&nbsp;             </td>
  61.             <td>
  62.                 &nbsp; &nbsp;<input id="Text1" type="text" name="cname" /></td>
  63.         </tr>
  64.         <tr>
  65.             <td class="style2">
  66.                 e-mail&nbsp;
  67.             </td>
  68.             <td>
  69.                 &nbsp; &nbsp;<input id="Text2" type="text" name="cemail" /></td>
  70.         </tr>
  71.         <tr>
  72.             <td class="style2">
  73.                 Comments&nbsp;
  74.             </td>
  75.             <td>
  76.                 &nbsp; &nbsp;<input id="Text3" type="text" name="ccomments"/></td>
  77.         </tr>
  78.     </table>
  79.  
  80.     <p style="text-align: center">
  81.         <input id="Submit1" type="submit" value="submit" onClick="addrecord(this.form)" />&nbsp;&nbsp;&nbsp;
  82.         <input id="Reset1" type="reset" value="reset" /></p>
  83.  
  84. </body>
  85. </html>
Feb 2 '10 #1
8 14310
Dormilich
8,658 Expert Mod 8TB
you are aware, that this will only work in IE?
Feb 2 '10 #2
Yes. this will only be used in a closed environment at this time. the office is Microsoft central.
Feb 2 '10 #3
acoder
16,027 Expert Mod 8TB
What problems are you having with the code? Error messages? Which line number?

Have you checked the archives for similar questions, e.g. this one?
Feb 2 '10 #4
At launch, I am getting the error at line 33 EXPECTED HEXADECIMAL DIGIT

when running, and I hit submit, I get an error at line 83 OBJECT EXPECTED
Feb 2 '10 #5
acoder
16,027 Expert Mod 8TB
What lines do these correspond to in the code?

I think part of your problem is using XHTML and including JavaScript code within the page. Either use HTML or include the code from a script file, and validate the page.
Feb 4 '10 #6
ifedi
60
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5.     <title>Project input Form</title> 
  6.     <style type="text/css"> 
  7.         .style1 
  8.         { 
  9.             width: 70%; 
  10.         } 
  11.         .style2 
  12.         { 
  13.             text-align: right; 
  14.             width: 261px; 
  15.         } 
  16.         #Text1 
  17.         { 
  18.             width: 191px; 
  19.         } 
  20.         #Text2 
  21.         { 
  22.             width: 189px; 
  23.         } 
  24.         #Text3 
  25.         { 
  26.             width: 190px; 
  27.         } 
  28.         #Button1 
  29.         {} 
  30.     </style> 
  31.     <SCRIPT LANGUAGE="JavaScript"> 
  32.     function addrecord (form) { 
  33.         var cn = new ActiveXObject("ADODB.Connection"); 
  34.         var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\aknab\My Documents\testingapp\users.accdb;Persist Security Info=False"; 
  35.         cn.Open(strConn); 
  36.         var rs = new ActiveXObject("ADODB.Recordset"); 
  37.         var SQL = "select count(*) from Customers"; 
  38.         rs.Open(SQL, cn); 
  39.         alert(rs(0)); 
  40.  
  41.         //below:why no closing single quote?
  42.         rs.AddNew 'Prepare the database to add a new record and add 
  43.         rs.Fields("name") = Request.Form("cname"); 
  44.         rs.Fields("email") = Request.Form("cemail"); 
  45.         rs.Fields("comments") = Request.Form("ccomments"); 
  46.  
  47.         //below:why no closing single quote?
  48.         rs.Update;   'Save the update 
  49.  
  50.         rs.Close(); 
  51.         cn.Close();   
  52.     } 
  53.     </script> 
  54. </head> 
  55. <body> 
  56.  
  57.     <p style="text-align: center"> 
  58.         Vetsulin Test page.<br /> 
  59.     </p> 
  60.     <table class="style1"> 
  61.         <tr> 
  62.             <td class="style2"> 
  63.                 Name&nbsp;             </td> 
  64.             <td> 
  65.                 &nbsp; &nbsp;<input id="Text1" type="text" name="cname" /></td> 
  66.         </tr> 
  67.         <tr> 
  68.             <td class="style2"> 
  69.                 e-mail&nbsp; 
  70.             </td> 
  71.             <td> 
  72.                 &nbsp; &nbsp;<input id="Text2" type="text" name="cemail" /></td> 
  73.         </tr> 
  74.         <tr> 
  75.             <td class="style2"> 
  76.                 Comments&nbsp; 
  77.             </td> 
  78.             <td> 
  79.                 &nbsp; &nbsp;<input id="Text3" type="text" name="ccomments"/></td> 
  80.         </tr> 
  81.     </table> 
  82.  
  83.     <p style="text-align: center"> 
  84.         <input id="Submit1" type="submit" value="submit" onClick="addrecord(this.form)" />&nbsp;&nbsp;&nbsp; 
  85.         <input id="Reset1" type="reset" value="reset" /></p> 
  86.  
  87. </body> 
  88. </html> 
  89.  
Let me confess that I haven't actually taken time to test your code.
However, please note the two lines of comment I've placed in your javascript above.

Above all, I'm not sure I'd expect
Expand|Select|Wrap|Line Numbers
  1.  <input id="Submit1" type="submit" value="submit" onClick="addrecord(this.form)" />
to work when this input and all the other input fields are NOT ENCLOSED IN ANY <form></form>
I suspect that the parent FORM is the object expected

Regards, Ifedi.
Feb 9 '10 #7
Dormilich
8,658 Expert Mod 8TB
to work when this input and all the other input fields are NOT ENCLOSED IN ANY <form></form>
I suspect that the parent FORM is the object expected
form elements do not submit if there’s no <form> element, that’s right.
Feb 9 '10 #8
raleti
1
use "microsoft.ace.oledb.12.0" driver instead of "Microsoft.Jet.OLEDB.4.0"
and chanage rs.Open(SQL, cn); to rs.Open(SQL, cn,1,3);

its worked from with above changes.
Jan 14 '15 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: hagarwal | last post by:
People, Here's my situation: 1. I have a web browser component that does not support Javascript (well it does, but we've disabled it) 2. I have to display some HTML in it, where the user has a...
2
by: xpcer | last post by:
i wanna to backup an access database using vb. if my database without password i can use Filecopy "database.mdb","D:\myback.mdb" but if my database with password, it can't work, and the...
0
by: leen85 | last post by:
helo everybody...i'm lina...i need your help...i have a problem in VB and Access...i have 38000 images for my company employee which size about 5GB to stored in database...as we know we cant stored...
0
by: rajabide4u | last post by:
How to insert data into ms access using javascript
1
by: ariel gons | last post by:
This is one of my project and also my thesis in school. How can I get data on database MYSQL using javascript function? Is there anybody here can help me with this problem.. Can anyone give...
3
by: Rajendran | last post by:
Hi all, I've installed pyodbc module to access my database (MS Access). I've setup a User level DSN to the database.mdb file. When I run my python code in the command prompt it is retrieving the...
2
by: franklin moses | last post by:
how do i insert textbox values to ms access using javascript
1
by: Mikhail Teterin | last post by:
Hello! A major application we are using allows extending itself with custom JavaScript. They embed Rhino implementation of JS (written in Java). There is no apparent built-in way to access...
1
by: irfanshariffa | last post by:
<html> <head> <script type="text/javascript" language="javascript"> function validate() { if (document.form.fname.value=="") { alert("Enter your Name"); document.form.fname.focus();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.