...

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



bhakti_thakkar
08-20-2008, 01: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?

A1ien51
08-20-2008, 01: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.

Eric

technica
08-21-2008, 10:36 AM
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

rnd me
08-21-2008, 10: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>

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum