Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts

    hyperlink to perform action before redirecting

    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
    Last edited by jasonc310771; 08-21-2008 at 12:38 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
    <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>

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    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

    Code:
    <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>

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by barkermn01 View Post
    var counter; // get previous value of counter

    // write value of counter to the DB
    how ?

  • #5
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    478
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SSJ View Post
    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

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by jasonc310771 View Post
    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.
    Last edited by Philip M; 08-21-2008 at 01:15 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •