Link to home
Start Free TrialLog in
Avatar of traport
traport

asked on

Passing a Coldfusion variable in an onClick function in href

I have an href

<a href="javascript:void(0);" onClick="showPopUp('currentRTIID=#currentRTIID#')">#fixedDisplayName#</a>

and it controls the show/hide of a lightbox.

I can't get the variable #currentRTIID# to pass in the function I'm using. Either that or I can't get the page it passes to (which is actually just showing/hiding a div.

Help!

Avatar of sajayc
sajayc
Flag of New Zealand image

Hi,
This should work,
You will need to put <cfoutput></cfoutput> tags around that line your code for the variables to be resolved.

Otherwise the variables will be sent to your browser with the hashes (#variable#)
Sorry, I just realised that when you pass variables into javascript, you only need to send the value.

If you publish you javascript function, I can check that you are retrieving the value correctly.

Javascript should look something like this:

function showpopup(lvcurrentrtiid)
{
The variable lvcurrentrtiid is what you use to do whatever you need to do.
}


Link should look like this:
<cfoutput><a href="javascript:void(0);" onClick="showPopUp(#currentRTIID#)">#fixedDisplayName#</a></cfoutput>



Just wrap your CF variable around the <cfoutput> Tag

<a href="javascript:void(0);" onClick="showPopUp('currentRTIID=<cfoutput>#currentRTIID#</cfoutput>')"><cfoutput>#fixedDisplayName#</cfoutput></a>

Open in new window

Avatar of traport
traport

ASKER

Thanks for the help but that's actually not the problem I'm having (apologies if I confused you). The problem I'm having is that the variable (which I can see in the link) is not carrying over to the hidden div when the link is clicked.

In other words, <a href="javascript:void(0);" onClick="showPopUp('currentRTIID=123555')">Jane Doe</a> , is not being carried into the div that showPopUp calls.

Thanks!

ASKER CERTIFIED SOLUTION
Avatar of dagaz_de
dagaz_de

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of traport

ASKER

Thank you!!!