4 Replies Latest reply on Apr 30, 2007 3:21 PM by insuractive

    using anchor to change a variable

    djc11 Level 1
      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?
        • 1. Re: using anchor to change a variable
          Dan Bracuk Level 5
          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.
          • 2. Re: using anchor to change a variable
            insuractive Level 3
            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.
            • 3. Re: using anchor to change a variable
              djc11 Level 1
              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.
              • 4. Re: using anchor to change a variable
                insuractive Level 3
                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.