1 Reply Latest reply on Jul 3, 2007 10:06 PM by MikeL7

    creating session variable from a form

    imjusthere2
      I have a form that takes keywords from the user to narrow down the displayed records. I want to assign the keywords to a session variable so when they visit other pages and return, the results are stilled narrowed down by their keywords. I know the code is <%Session("searchvalue")=Request.Form("keywords")%> but I don't know where to put it so it assigns it before going to the results page.

      The following doesn't work but can I do something like this?

        • 1. Re: creating session variable from a form
          MikeL7 Level 1
          Two ways to make it work, You need to put the Session("searchvalue") = Request.form("keywords") code on the result page, if you want to have your Session filter the recordset then put the code before the recordset then use the session var to filter, with a if statement so they can come back to thepage from a different one and still have the session value, like this:

          IF Request.form("keywords") <> "" THEN 'if request does not equal nothing
          Session("searchvalue") = Request.form("keywords")
          End IF

          OR you could make the page with the form post to itself and then assign the session, then do a redirect, which could give you the option of redirecting to different pages. Like this
          make form post to self:
          <form id="form1" name="form1" method="post" action="<%= CStr(Request.ServerVariables("SCRIPT_NAME")) %>">
          <input type="text" name="keywords">
          <input type="submit" name="submit" value="search">
          </form>
          Then add code like this to the page before the <!DOCTYPE html PUBLIC line
          <%
          If request.form("keywords") <> "" THEN
          Session("searchvalue") = Request.form("keywords")
          'You can put different redirects here, like a radio button set of options: Print, View
          If Request.form("radio") = "Print" Then
          response.redirect ("printword.asp")
          end if
          If Request.form("radio") = "View" Then
          response.redirect ("viewword.asp")
          end if'
          'Or just one page redirect
          reponse.redirect ("testsearch.asp")
          End If
          %>