I set up an Access database with a text field to record the website name and a date field to record the date/time of the access. I have set up a page with various anchors set up to call up different websites. When the user clicks a particular anchor, I want to be able to record this information to the database. Is there an event which can be connected to the anchor and update the database?
Record Calls to URL in Access Database
Collapse
X
-
Hi rmurgia,
You could set up an intermediate page between the page you are linking from and the page you are linking to. On this intermediate page you could update the database then forward the user to the appropriate page using a response.redire ct.
To do this successfully you will need to pass the URL of the page that the user is trying to link to through the querystring which can be tricky. It would be easier to pass an ID value which you could use to look up your database (where you'll need to store the ID and URL as well as your other data) and return the appropriate URL.
Here's a quick example:
Page1.asp
LinkClicked.aspCode:<a href="LinkClicked.asp?PageID=1">Link 1</a> <a href="LinkClicked.asp?PageID=2">Link 2</a>
Does this make sense? Let me know how you get on,Code:iPageID = Request.querystring("PageID") **** Use iPageID to update your database and retrieve the actual url of the requested page (which i've called sURL) **** Response.Redirect sURL
Dr B -
Execute vbscript from javascript
I am trying to store the link the user clicked on in an Access database. I have completed the Access coding which is NOT included below. I have also completed the code to determine the link, which is included below. When the user clicks myAnchor2, http://www.cnn.com is successfully stored since it can be displayed with the document.write command. However, when I try to save it to a text field on the form, it says: document.frmURL HistoryCheck.UR LNM is Null or Not an Object. I believe that since we did not click the submit button that URLNM does not yet exist. Is there a way to have say 5 different anchors displayed, and have the user click one of them, determine what the URL was with the code listed below, and then store it to a text field and write it to an Access database? I think what it would have to involve is somehow triggering the submit button from the Javascript and also trigging the vbscript from the Javascript which will save the value in the text field to the Access database. Is this possible?
Code:function FindLink() { document.write(document.getElementById('myAnchor2').href); document.frmURLHistoryCheck.URLNM.value = document.getElementById('myAnchor2').href } <form method="POST" action="URLHistoryCheck2.asp" name="frmURLHistoryCheck" > <a id="myAnchor2" href="http://www.cnn.com">CNN</a> <input type="button" onclick="FindLink()" value="Find link"> <input type="text" name="URLNM" value="Test">Test Field</input> </form>Comment
-
rmurgia,
I have merged this thread with the previous one you posted as they are on the same subject.
Javascript is a client side language and ASP is a server side language which means that, although your Javascript function knows the URL that has just been clicked, the only way you are able to update the database with that information is to pass it back to the server through a querystring or form. This means that you will have to either link the page back to itself or an intermediate page to process the database update before redirecting to the desired page as per my reply to your original post.
There is no way to update the database without posting the data back to the server in some way.
You could use your FindLink() function to pass the value of the desired URL and redirect to the intermediate page if you prefer rather than following the example I gave above where you stored the URL's in your database.
Dr BComment
-
Comment