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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    how to pass a javascript function to <a href>

    hi all,
    i have to create a link on the page which onclick the user should not only be diverted to that page (users.php) but also dynamically call a function which is written on that page ( function in users.php). How will i do it?

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Not going to happen with the onclick.

    You would have to set some value in a querystring, read the querysting on the new page, and fire it.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Posts
    107
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well for diverting to other page u can use below code:

    document.location.href='users.php';

    in Javascript onclick function

    Like this:

    function fOnlck()
    {
    document.location.href='users.php';
    }

    and now on body onload event of the new page (i.e. users.php) call a another javascript function that will call u r desired function which should get executed once the page is loaded.

    Hope this helps you
    Programming & Webmaster Forum - AdSense Revenue Sharing forum

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    you can simply tack parameters onto the url of the php page you are sending the user to.

    instead of

    <a href="users.php"> users</a>

    use

    <a href="users.php?user=bob;&secure=0"> users</a>


    you can use the same javascript that builds the urls to include the values of local variables into the url.



    ---------
    edit: oops, A1ien51 already said something close...

    still, you can use the onlclick function and the redirect to do the same thing in building the redirect url as you can making the href...
    Last edited by rnd me; 08-21-2008 at 10:22 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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