...

View Full Version : hyperlink to perform action before redirecting



jasonc310771
08-21-2008, 01:14 AM
would Javascripts be used to perform the following.
link being click would increase a counter in my Db before the link it visited.

<a href="www.site.com" (javascript code with 'site 1' included in the details checked in DB for it to update the correct line in the DB)>site1</a>

can anyone suggest a way of doing this ?

thanks in advance

Philip M
08-21-2008, 08:30 AM
<a href = "#" onclick = "update()">Site 1</a>

<script type = "text/javascript">
var counter; // get previous value of counter
function update () {
counter ++;
// write value of counter to the DB
window.location = "http://www.site.com";
}
</script>

barkermn01
08-21-2008, 12:39 PM
Will people stop using # as a link for Text Clicks

If you want to call a Javascript Function from a text link use this it faster and stop the page reloading

<a href="javascript:*fuct name*;">Text</a>

SO Philip was right just the Text link at the top needs changing



<a href="javascript:update();">Site 1</a>

<script type = "text/javascript">
var counter; // get previous value of counter
function update () {
counter ++;
// write value of counter to the DB
window.location = "http://www.site.com";
}
</script>

jasonc310771
08-21-2008, 12:56 PM
var counter; // get previous value of counter

// write value of counter to the DB


how ?

SSJ
08-21-2008, 01:34 PM
You can implement it using Ajax. Call a function which will make a XMLHTTP Request to another php or asp page. You need to have a server side coding page to access the database

jasonc310771
08-21-2008, 01:59 PM
You can implement it using Ajax. Call a function which will make a XMLHTTP Request to another php or asp page. You need to have a server side coding page to access the database

sorry to sound stupid, which i am..#

but how?

i have no idea

Philip M
08-21-2008, 02:13 PM
but how? i have no idea

I rather think that all this is too advanced for you. You are trying to run before you can crawl. SSJ gave you the answer but you will need more advanced coding skills to implement it.

Barkermn01 - Sorry, I do not agree. And neither does abduraooft in another post.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum