We help IT Professionals succeed at work.
Get Started

Updating database records in classic ASP using javascript

ZKM128 asked
Last Modified: 2015-06-25

How do I update database record (MS Access) in classic ASP when javascript onclick event is triggered on the image button?
Here's the detailed description of what I'm trying to achieve.

I have created a recordset "rsMembers" in my (classic) ASP page for displaying a record stored in the MS Access database table and bound the table field data on the ASP page for the initial display of the personal details record data to the user when the page is loaded on the browser. The ASP page looks like the image shown below.

The ASP page on the browser
What I want to achieve is when the user clicks the blue circular button on the page, I want the javascript onclick event script to trigger/execute vbscript ASP update codes shown below.

   Set conn = Server.CreateObject("ADODB.Connection")
   conn.Open Session("DSN=MembersSampleDSN")
   Set rsMembers = Server.CreateObject("ADODB.Recordset")
   rsMembers.Open "MembersTable", conn, 1, 3, 2

   ' Update the value of 'DataPrinted' field for the currently displayed record
   rsMembers ("DataPrinted") = "Yes"
   rsMembers .Update

   rsMembers .Close

Open in new window

I know how to update MS Access database records using ASP when the ASP page is loaded or when the submit button inside a form is pressed but I don't know how to achieve this using javascript -- onclick event of the image button. That is, I want to know the way of changing the database record without submitting/opening the ASP page.
Is this possible? Please show me the correct javascript codes for executing particular block of vb codes shown above if possible.

<img id="BlueButton" onclick="DataPrinted" />

    function DataPrinted() { 

Open in new window

Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 3 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE