Solved

Passing a Coldfusion variable in an onClick function in href

Posted on 2011-03-02
6
1,099 Views
Last Modified: 2012-05-11
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!

0
Comment
Question by:traport
6 Comments
 
LVL 3

Expert Comment

by:sajayc
ID: 35022913
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#)
0
 
LVL 3

Expert Comment

by:sajayc
ID: 35022965
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>



0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35023310
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

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:traport
ID: 35025948
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!

0
 
LVL 3

Accepted Solution

by:
dagaz_de earned 500 total points
ID: 35028438
You have aProblem in your JS Syntax:

If you pass 2 Values to a JS function you must seperate them with a comma, not a '='.

showPopUp('currentRTIID=123555') is false

showPopUp('currentRTIID','123555') is good

in your JS you do it like this



function showPopUp ( param, val){

// now you can use param which holds the first value you submitted to Your JS function ( currentRTIID)

// and second you can use val which holds the first value you submitted to Your JS function ( 123555)

var theurl = 'http://your-url.com/your-page.cfm?' + param + '=' + val + '';

window.open(""+theurl +"", "YourWindowName", "width=300,height=400,left=100,top=200");

}
0
 

Author Closing Comment

by:traport
ID: 35032850
Thank you!!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now