Results 1 to 2 of 2

Thread: cookies

  1. #1
    Join Date
    Dec 1969

    Default cookies

    i am using asp with javascript. i wanted to retain the form input values on my form. i used this javascript eg given in this url with this i am able to retain the values but whats happening is the when i open the form i get all the values by default entered into it... <BR><BR>normally when u login to hotmail and try to give login name we get multiple options as a drop down, say janet & at the bottom alex. <BR><BR>how is it possible? will be really helpful is someone can suggest on it.. <BR>thanks a lot.

  2. #2
    Join Date
    Dec 1969

    Default That's a bit more involved...

    ...and not quite as straightforward. First of all, you&#039;ll have to store the values that the user entered in an array, which you can then store in the cookie that you currently use. It doesn&#039;t have to be an actual array, but you could have a comma separated value list, or a pipe (&#124) separated value list, like this:<BR><BR>"Peter&#124John&#124Mark&#124Steven"< BR><BR>You can split this into an array for processing purposes really easily using the Split() function.<BR><BR>Now, at the point where you save the username in your cookie, you don&#039;t just replace the existing value with what you got from the form. Instead, you read out what you currently got. If the value from the form already exists, you don&#039;t do anything. Otherwise, you add it to the "array":<BR><BR>Dim sUsername, sArray<BR><BR>sUsername = Request("UsernameFromForm")<BR>sArray = &#060;get username "array" from cookie - just like you get the username from the cookie&#062;<BR><BR>If Instr("&#124" & sArray & "&#124", "&#124" & sUsername & "&#124") &#062; 0 Then<BR>&#039; Username already exists - don&#039;t do anything<BR>Else<BR>&#039; Username doesn&#039;t exist - add it to the array<BR>sArray = sArray & "&#124" & sUsername<BR>End If<BR><BR>&#060;now put the sArray value back into the cookie - just like you would put in the username&#062;<BR><BR>Now, so far so good. You&#039;re storing all possible usernames in the cookie. All you have to do now is amend your username/password form to allow for the drop down, so write out an &#060;select&#062;&#060;option&#062; box. Then get the array of usernames from the cookie, split it using Split("&#124"), sort it alphabetically, if you want, and then write it out. Easy peasy.<BR><BR>Oliver.

Posting Permissions

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