By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

HTML Database access using Javascript

P: 7
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
Share this Question
Share on Google+
8 Replies


Dormilich
Expert Mod 5K+
P: 8,639
you are aware, that this will only work in IE?
Feb 2 '10 #2

P: 7
Yes. this will only be used in a closed environment at this time. the office is Microsoft central.
Feb 2 '10 #3

acoder
Expert Mod 15k+
P: 16,027
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

P: 7
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
Expert Mod 15k+
P: 16,027
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
P: 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
Expert Mod 5K+
P: 8,639
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

P: 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

Post your reply

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