Solved

Passing a Coldfusion variable in an onClick function in href

Posted on 2011-03-02
6
1,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…

726 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