469,271 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Record Calls to URL in Access Database

63
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?
Jun 11 '08 #1
5 1670
DrBunchman
979 Expert 512MB
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.redirect.

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
Expand|Select|Wrap|Line Numbers
  1.  
  2. <a href="LinkClicked.asp?PageID=1">Link 1</a>
  3. <a href="LinkClicked.asp?PageID=2">Link 2</a>
  4.  
LinkClicked.asp
Expand|Select|Wrap|Line Numbers
  1.  iPageID = Request.querystring("PageID") 
  2.  
  3. **** Use iPageID to update your database and retrieve the actual url of the requested page (which i've called sURL) ****
  4.  
  5. Response.Redirect sURL
  6.  
Does this make sense? Let me know how you get on,

Dr B
Jun 11 '08 #2
rmurgia
63
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.frmURLHistoryCheck.URLNM 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?
Expand|Select|Wrap|Line Numbers
  1.  
  2. function FindLink()
  3. {
  4. document.write(document.getElementById('myAnchor2').href);
  5. document.frmURLHistoryCheck.URLNM.value = document.getElementById('myAnchor2').href
  6. }
  7.  
  8. <form method="POST" action="URLHistoryCheck2.asp" name="frmURLHistoryCheck" >
  9.  
  10. <a id="myAnchor2" href="http://www.cnn.com">CNN</a>
  11. <input type="button" onclick="FindLink()" value="Find link">
  12.  
  13. <input type="text" name="URLNM" value="Test">Test Field</input>
  14. </form>
  15.  
Jun 11 '08 #3
DrBunchman
979 Expert 512MB
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 B
Jun 11 '08 #4
rmurgia
63
I passed to an intermediate page, saved to the database, and then re-directed to the correct page. Thanks for the help.
Jun 24 '08 #5
DrBunchman
979 Expert 512MB
Good stuff! Glad you got it working.

Dr B
Jun 25 '08 #6

Post your reply

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

Similar topics

1 post views Thread by Andante.in.Blue | last post: by
9 posts views Thread by Joshua.Buss | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.