adding all cookies in a loop

Results 1 to 2 of 2

Thread: adding all cookies in a loop

  1. #1
    Join Date
    Dec 1969

    Default adding all cookies in a loop

    Hello,<BR><BR>could someone help me? I am trying to add together numbers which are saved in cookies by using a loop. My problem is when I do this it seems to only pull the latest cookie and is adding that cookie to itself over and over until it reaches the end of the cookies. What I need is for it to pull each of the cookies and add them together.<BR><BR>This is the code I am using:<BR><BR>For each cookie in Request.Cookies <BR>mynumber= Request.Cookies("item" & this)("cost")<BR>mynumber= Replace(mynumber,"$","")<BR>&#039;response.write "mynumber= " & mynumber<BR><BR>temptotal= temptotal + mynumber<BR>&#039;response.write "temptotal= " & temptotal<BR><BR><BR>next<BR><BR><BR>Response.writ e "Total Cost: " & temptotal<BR><BR><BR><BR>The result I am getting is that it is looping "x" times for each cookie, but only getting the most recent cookie. How do I get this to work so I am pulling each of the cookies, so I can add them together.<BR><BR>Thanks for your help<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default you loop cookies like this

    [code language="VBSCRIPT"]<BR>&#060;% <BR>&#039;Declare counter variables<BR>Dim Cookie, Subkey<BR><BR>&#039;Display the entire cookie collection.<BR>For Each Cookie in Request.Cookies<BR> Response.Write Cookie & "<BR>"<BR> If Request.Cookies(Cookie).HasKeys Then<BR> &#039;Display the subkeys<BR> For Each Subkey in Request.Cookies(Cookie)<BR> Response.Write Subkey & "=" & Request.Cookies(Cookie)(Subkey) & "<BR>"<BR> Next<BR> Else<BR> Response.Write "No subkeys in this cookie <BR>"<BR> End If<BR>Next <BR>%&#062;<BR>&#060;/code]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts