473,406 Members | 2,816 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,406 software developers and data experts.

javascript add records in MS DB by using ASP vbscript recordset varible

hi
help me i m so much stuck int he code and i have no time ....

i used ASP VBscipt and javascript functions with MS database

javascript function add records in MS DB by using ASP vbscript recordset varible

when user click the save button then some values save in the database so i write javascript function to add the records...

here is the code
---------------------------------------------------------------------------------------
2.asp
-------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <!--#include file="con_db.asp" -->
  2.  
  3.  
  4. <%
  5.  
  6.  
  7.  
  8.  
  9.                             dim rs1
  10.                             set rs1= server.CreateObject("ADODB.recordset")
  11.                             rs1.ActiveConnection=DB_string
  12.                             rs1.Source="Select * from physical_usage_data"
  13.                             rs1.Cursortype=2
  14.                             rs1.locktype=3
  15.                             rs1.open()
  16.                             rs1_numRows = 0
  17.  
  18.                             dim rs2
  19.                             set rs2= server.CreateObject("ADODB.recordset")
  20.                             rs2.ActiveConnection=DB_string
  21.                             rs2.Source="Select * from product_data"
  22.                             rs2.Cursortype=1
  23.                             rs2.locktype=2 
  24.                             rs2.open()
  25.                             rs2_numRows = 0
  26.  
  27.  
  28. %>
  29. <script language="javascript">
  30.  
  31.         var d2_array=new Array;
  32.         var p2_array=new Array;
  33.         var P2=0;
  34.         var D_html;
  35. </script>
  36.  
  37. <script language="javascript">
  38.  
  39.  
  40. function showHint(p_id, p_val)
  41. {
  42. if (p_id=='Detergent')
  43.     {
  44.          p2_array[P2]=p_val;
  45.     <%
  46.     rs2.movefirst
  47.     if not(rs2.eof and rs2.bof) then
  48.         do until rs2.eof
  49.             for i=1 to rs2.recordcount
  50.     %>
  51.  
  52.                 if (p_val=='<%=rs2.fields.item("PRODUCT").value%>')
  53.                  {   
  54.                      p2_array[P2]=p_val;
  55.                      d2_array[P2]='<%=rs2.fields.item("PROD_ID").value%>'+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+'<%=rs2.fields.item("PROD_DESC").value%>';
  56.                      P2++;
  57.                  }
  58.     <%
  59.     rs2.movenext
  60.            next
  61.         loop
  62.     end if
  63.     %>
  64.                  D_html="<table id='Table2'>";
  65.                 for (i = 0; i<=d2_array.length-1; i++)
  66.                     {
  67.                         D_html+="<tr><td nowrap>";
  68.                         D_html+=d2_array[i];
  69.                         D_html+="&nbsp;&nbsp;&nbsp;</td><td><input type='text' size='10'>gallons &nbsp;&nbsp;&nbsp;&nbsp;";
  70.                         D_html+="</td><td><input type='button' value='Remove' onclick='P2_deleteRow(this)'></td></tr>";
  71.                     }
  72.                         D_html+="</table>";
  73.                         document.getElementById("Detergent").innerHTML=D_html;
  74.  
  75.  
  76.  
  77.     }
  78. }
  79.  
  80. function P2_deleteRow(r)
  81.   {
  82.   var i=r.parentNode.parentNode.rowIndex;
  83.   d2_array.splice(i,1);
  84.   p2_array.splice(i,1);
  85.   document.getElementById('Table2').deleteRow(i);
  86.    P2=d2_array.length;
  87.   }
  88.  
  89.  
  90.  
  91. ///////////////////////////////////////////////////////////////////////////////////////////
  92.  
  93. function save() {
  94. var record
  95.     <%rs2.movefirst%>
  96.     for (t = 0; t<=p2_array.length-1; t++){
  97.             record=p2_array[t];
  98.         <%if not(rs2.eof and rs2.bof) then
  99.             do until rs2.eof
  100.                 for i=1 to rs2.recordcount
  101.         %>
  102.  
  103.                     if (record == '<%=rs2.fields.item("PRODUCT").value%>')
  104.                      {   
  105.  
  106.                          <%
  107.                          rs1.AddNew
  108.                              rs1.fields("PROD_ID")=rs2.fields("PROD_ID").value      
  109.                          rs1.Update
  110.  
  111.                          %>
  112.                          document.getElementById("a").innerHTML="done";
  113.                      }
  114.         <%
  115.         rs2.movenext
  116.                next
  117.             loop
  118.         end if
  119.         %>
  120.   }
  121. }
  122.  
  123. </script>
  124.  
--------------------------------------------------------
here is the other file coding where i m callng these functions
---------------------------------------------------------------------------------------
1.asp
-------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT"%>
  2. <% response.Buffer=true %>
  3. <!--#include file="2.asp" -->
  4.  
  5. <%
  6.                             dim rs,rs4                
  7.                             set rs= server.CreateObject("ADODB.recordset")
  8.                             rs.ActiveConnection=DB_string
  9.                             rs.Source="SELECT DISTINCT sales_data.PRODUCT, product_data.PROD_CATEGORY, sales_data.CUST_ACCT_ID FROM sales_data INNER JOIN product_data ON sales_data.PROD_ID = product_data.PROD_ID WHERE (((sales_data.CUST_ACCT_ID)= 'P11618675'))"
  10.                             rs.Cursortype=1
  11.                             rs.locktype=2 
  12.                             rs.open()
  13.                             rs_numRows = 0
  14.  
  15.  
  16.                             set rs4= server.CreateObject("ADODB.recordset")
  17.                             rs4.ActiveConnection=DB_string
  18.                             rs4.Source="SELECT DISTINCT physical_usage_data.PROD_ID, physical_usage_data.PROD_CATEGORY, product_data.PROD_DESC, physical_usage_data.PROD_USAGE_AMT, physical_usage_data.PROD_USAGE_DT, physical_usage_data.ENTER_BY_IND, physical_usage_data.CRE_DT FROM physical_usage_data INNER JOIN product_data ON physical_usage_data.PROD_ID = product_data.PROD_ID WHERE (((physical_usage_data.CUST_ACCT_NBR)= 'P11618675'))"
  19.                             rs4.Cursortype=1
  20.                             rs4.locktype=2 
  21.                             rs4.open()
  22.                             rs4_numRows = 0
  23.  
  24. %>
  25. <html>
  26. <head>
  27. <title>java</title>
  28. </head>
  29. <body>
  30.  
  31.  
  32.   <%
  33.             if not(rs4.eof and rs4.bof) then
  34.  
  35.                 rs4.movefirst
  36.                 response.write("<table id='myTable1'>")
  37.                 do until rs4.eof
  38.                      for i=1 to rs4.recordcount
  39.                         if (rs4.fields.item("PROD_CATEGORY").value)="Detergent" then
  40.  
  41.                             response.Write("<tr><td>"&rs4.fields.item("PROD_ID").value&"</td><td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;"&rs4.fields.item("PROD_DESC").value&"</td><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' id='txt' size='10' readonly='text' value='"&rs4.fields.item("PROD_USAGE_AMT").value&"'>gallons</td><td>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='Remove' onclick='deleteRow(this,myTable1.id)'></td></tr>")
  42.                                 'response.Write(rs4.fields.item("PROD_ID").value &"&nbsp;&nbsp;&nbsp;&nbsp;"&rs4.fields.item("PROD_DESC").value&"&nbsp;&nbsp;&nbsp;&nbsp;")
  43.                                 'response.Write("<input type='text' id='txt' size='10' value='"&rs4.fields.item("PROD_USAGE_AMT").value&"'/><br>")
  44.                                 'response.Write("<input type='button' value='Remove' ><br>")
  45.  
  46.                         end if
  47.                         rs4.movenext
  48.                      next
  49.                 loop
  50.                 response.write("</table>")
  51.             end if
  52.  
  53.             %> 
  54.             <a id="a"></a><br>
  55.             <a id="b"></a><br>
  56.   <a id="Detergent"></a><br>
  57.     <select id="Detergent" onchange="showHint(this.id,this.value)">
  58.                   <option>Choose Product..</option>
  59.                   <%
  60.             rs.movefirst
  61.             if not(rs.eof and rs.bof) then
  62.                 do until rs.eof
  63.                      for RD=1 to rs.recordcount
  64.                         if (rs.fields.item("PROD_CATEGORY").value)="Detergent" then
  65.                             %>
  66.                                     <option  value="<%=rs.fields.item("PRODUCT").value%>">    <%=rs.fields.item("PRODUCT").value%></option>
  67.                                 <%
  68.                         end if
  69.                         rs.movenext
  70.                      next
  71.                 loop
  72.             end if
  73.             %>
  74.   </select> 
  75. <input type="button" value="Save" onclick="javascript:save('true')"/>
  76. <%
  77. rs2.close
  78. set rs2=nothing
  79. rs1.close
  80. set rs1=nothing
  81. rs.close
  82. set rs=nothing
  83. rs4.close
  84. set rs4=nothing
  85. %>
  86.  
  87. </body>
  88. </html>
  89.  
-------------------------------------------------------------
reply me fast ........
thanks
ddirector
Nov 20 '07 #1
1 3334
acoder
16,027 Expert Mod 8TB
JavaScript can't interact with a database directly.

Either use Ajax to make a request to the server to save the data or put the data in a form and submit the form to a server-side script which saves the data to the database.
Nov 21 '07 #2

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

Similar topics

3
by: Dana | last post by:
I have a form with a couple of dropdown fields. the dropdown fields get the value from one table which is a reference table. The table consists of 3 columns - type, id, name. An example would...
3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
9
by: crjunk | last post by:
I was asked to update an ASP web page that is executed by an ASP.NET aspx web form. I have no control over modifying the ASPX page, so I cannot see any meaningful error message from my ASP page...
13
by: Eric Robinson | last post by:
Hello, My ASP code creates an ADO recordset object on the server. Later on the same page, I have a javascript code snippet that I use to dynamically populate a drop-down box based on choices...
1
by: --[zainy]-- | last post by:
Hello Guyz.. I want to assign a varascript value to a session object in javascript function... like i have an image and onClick i am calling a function sort_(str).. Now i want to assign this...
1
by: NEC | last post by:
I am using access 2000 and have a DAP that I created from a table. What I am trying to do is essentially create a find command that will search all records in the DAP based on user input. I have...
1
by: mikegolden | last post by:
An application I'm working on makes extensive use of output parameters and return values, thus forcing me to use the ADODB Command object to execute the stored procs. For recordset returning stored...
1
by: sheldonlg | last post by:
I have inherited code with a TDC control. In this file, there are two javascripts of interest. One of these is a function, filter(), which is inside <script language=javascript></script>. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.