I set a variable on the first creation of the cookie and checked for the existence of it in the second conditional statement, if It exists then I am not running the second block of code. Good idea...Bad idea...?
So now it reads <!---IF OUR COOKIE IS NOT SET, SET IT NOW ---> <cfif not isDefined('cookie.testCookie') AND isDefined('form.test')> <CFCOOKIE name="testCookie" value="#form.test#" expires="never"> <!---IS THIS OUR FIRST TIME THROUGH?---> <cfset firstTime = 1> </cfif> <!---IF OUR COOKIE IS SET AND THE LEN IS LT 6, ADD TO IT---> <cfif isDefined('cookie.testCookie') AND listLen(cookie.testCookie, ",") LT 6 AND isDefined('form.test') AND not isDefined("firstTime")> <cfset searchList = listAppend(cookie.testCookie, form.test, ",")> <CFCOOKIE name="testCookie" value="#searchList#" expires="never"> </cfif> Doug B. ----- Original Message ----- From: "Doug Brown" <[EMAIL PROTECTED]> To: "CF-Talk" <cf-talk@houseoffusion.com> Sent: Monday, January 22, 2007 6:45 AM Subject: Cookie & list help please > Please check out the below code, I would like to show users a previous search history and everything seems to work ok except that on the first time through it appends the seach phrase twice. I understand why it is happening, (due to the 2nd conditional statement) but cannot figure out a better way. Maybe someone can test it out for me, and give me a pointer. Thanks a bunch!!! > > > > cookieTest.cfm > > <!---IF OUR COOKIE IS NOT SET, SET IT NOW ---> > <cfif not isDefined('cookie.testCookie') AND isDefined('form.test')> > <CFCOOKIE name="testCookie" value="#form.test#" expires="never"> > </cfif> > <!---IF OUR COOKIE IS SET AND THE LEN IS LT 5, ADD TO IT---> > <cfif isDefined('cookie.testCookie') AND listLen(cookie.testCookie, ",") LT 6 AND isDefined('form.test')> > <cfset searchList = listAppend(cookie.testCookie, form.test, ",")> > <CFCOOKIE name="testCookie" value="#searchList#" expires="never"> > </cfif> > <!---IF OUR COOKIE IS LEN IS EQ 5 THEN DELETE THE FIRST ELEMENT AND APPEND THE LIST---> > <cfif isDefined('cookie.testCookie') AND listLen(cookie.testCookie, ",") GTE 6 AND isDefined('form.test')> > <cfset deleted = listDeleteAt(cookie.testCookie, "1")> > <CFCOOKIE name="testCookie" value="#deleted#" expires="never"> > </cfif> > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <link rel="stylesheet" href="style.cfm" /> > <script> > function showhide(id){ > if (document.getElementById){ > obj = document.getElementById(id); > if (obj.style.display == "none"){ > obj.style.display = ""; > } else { > obj.style.display = "none"; > } > } > } > </script> > <body> > <cfoutput> > <form name="form1" action="cookieTest.cfm" method="post"> > <input type="text" name="test" onclick="showhide('script'); return(false);" /><input type="submit" value="Test Cookie" /> > </form> > <div style="display: none; position:relative; top:0px; left:0px; width:152; background-color:##DAE4E4; border: 1px solid; color:##666666;" id="script"> > <table width="100%" cellpadding="1" cellspacing="0" border="0"> > <tr> > <td class="bblackfont">Recent Searches</td> > <td><img src="images/buttn-notok.gif" border="0" onclick="showhide('script'); return(false);" /></td> > </tr> > </cfoutput> > <cfif isDefined('cookie.testCookie')> > <cfloop list="#cookie.testCookie#" delimiters="," index="i"> > <cfoutput> > <tr> > <td colspan="2" class="nblackfont"><a href="">#i#</a></td> > </tr> > </cfoutput> > </cfloop> > </cfif> > </table> > </div> > > </body> > </html> > > > Doug B. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:267122 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4