Skip to main content
October 24, 2008
Question

Clear a variable

  • October 24, 2008
  • 5 replies
  • 438 views
How do I clear a variable? I tried to use Replace and it told me I could not use "" as the substring2.

I want to display a variable if its in the URL and then after I display it I want to clear it. Is this possible? What's happening is that if someone comments on a picture in my app, it goes to an insert page then redirects back to the picture page with the comment in the URL. That's good if they only do it once. If they comment again it shows both comments in the URL.
    This topic has been closed for replies.

    5 replies

    October 25, 2008
    I need to display it in the URL because the controller page redirects back to the page they commented with cflocation. Is there another way to do this?

    Setting the variable to "" doesn't do me any good because it still considers that as a variable.

    I did figure out a solution though.
    October 25, 2008
    I need to display it in the URL because the controller page redirects back to the page they commented with cflocation. Is there another way to do this?

    Setting the variable to "" doesn't do me any good because it still considers that as a variable.

    I did figure out a solution though.
    Inspiring
    October 25, 2008
    Why don't you simply not display the comment in the url?
    BKBK
    Community Expert
    Community Expert
    October 25, 2008
    Specializing what Ian says, you would, after displaying the variable, do

    <cfset URL.myVariable = "">

    or

    StructDelete(URL,"myVariable")



    Inspiring
    October 24, 2008
    idesdema wrote:
    > How do I clear a variable? I tried to use Replace and it told me I could not
    > use "" as the substring2.
    >
    > I want to display a variable if its in the URL and then after I display it I
    > want to clear it. Is this possible? What's happening is that if someone
    > comments on a picture in my app, it goes to an insert page then redirects back
    > to the picture page with the comment in the URL. That's good if they only do
    > it once. If they comment again it shows both comments in the URL.
    >

    <cfset myVariable = "">

    OR

    StructDelete(scope,"myVariable")
    I.E.
    StructDelete(variables,"myVariable")
    OR
    StructDelete(session,"myVariable")