Skip to main content
Inspiring
April 27, 2007
Question

using anchor to change a variable

  • April 27, 2007
  • 4 replies
  • 355 views
I want to have an anchor <a> , not a button, change a CF variable. First I was trying to link the anchor to a javascript but since the js was client side it wasn't working. I couldn't figure out how I could access the variable directly from the anchor tag either. My brain is fried from a long day today but I just can't seem to figure out how to do this. Any ideas out there?
This topic has been closed for replies.

4 replies

Inspiring
April 30, 2007
You should be able to format all your links like this:

MyPage.cfm
---------------------
<cfparam name="bShowSection" default="">
<a href="myPage.cfm?bShowSection=first_section">+</a> First Section
<cfif URL.bShowSection eq "first_section">
<!--- process code, include file, run query, etc --->
</cfif>

You could also use JavaScript to control your show/hide functionality, which would be much quicker response-wise, but would require you generate the code for all your expanded sections at once.
djc11Author
Inspiring
April 30, 2007
I'm creating a table with subtables that can be included by clicking a (+) on expandable areas. I figured if I toggled a boolean var, when a plus (or minus), was clicked the page would be refreshed with the table displaying the new query depending on which vars were set to true or false.
Inspiring
April 30, 2007
It sounds like Dan's suggestion is your best bet - you can even link to the same page, passing a URL variable at the end of the link that you can use to change your CF variable:

myPage.cfm
<cfparam name="myVarA" defalut="B">
<cfif isDefined("URL.myVar1")>
<cfset myVarA = URL.myVar1>
</cfif>

<cfoutput>
<a href="myPage.cfm?myVar1=foo">#myVarA #</a>
</cfoutput>

Can you tell us a little more about what you're trying to accomplish? There may be a better solution to your problem.
Inspiring
April 28, 2007
Link the anchor tag to another cf page and change the variable there.

iframes might be helpful. More helpful than the preceding paragraph in fact.