View Full Version : how to pass a javascript function to <a href>

08-20-2008, 02:41 PM
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?

08-20-2008, 02:50 PM
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.


08-21-2008, 11:36 AM
Well for diverting to other page u can use below code:


in Javascript onclick function

Like this:

function fOnlck()

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

rnd me
08-21-2008, 11:19 PM
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>


<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...