Results 1 to 2 of 2

Thread: session for list/menu problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100

    session for list/menu problem

    Hi all.
    I use list/menu in my web application.
    I am having problem for the list/menu to hold the value entered by user if there are alert message displayed after clicking submit button.
    The page will be refreshed and I want the same data to be hold there.
    So, I have used session() to store the data. But, the problem is it works only with textfield not for the list/menu. Only textfield in the page can store the data. May be, I didnt know the correct code for that.

    Here, I enclose my code for the list menu and hope that anyone here can help me correct the code. Thanks in advance.

    HTML Code:
    <select name ="negeri" class="text_normal" id="negeri">
    <%
    set gnegeri = server.CreateObject("adodb.recordset")
    gnegeri.open "select * from negeri" ,conn
    if not gnegeri.eof then
        for y=1 to gnegeri.recordcount
    %>
    <option value="<%=gnegeri("id")%>" <%if gnegeri("id") = session("negeri") then response.Write("selected") end if%>>
    <%=gnegeri("nama_negeri")%></option>

  2. #2
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: session for list/menu problem

    I wouldn't place code within the control elements
    VB Code:
    1. <select name ="negeri" class="text_normal" id="negeri">
    2. <%
    3. dim bSelected
    4. set gnegeri = server.CreateObject("adodb.recordset")
    5. gnegeri.open "select * from negeri" ,conn
    6. if not gnegeri.eof then
    7.     for y=1 to gnegeri.recordcount
    8.        if gnegeri("id")=session("negeri") then
    9.           bSelected="selected"
    10.        else
    11.           bSelected=""
    12.        end if
    13.  
    14.  
    15. %>
    16. <option value="<%=gnegeri("id")%>" <%=bSelected%>>
    17. <%=gnegeri("nama_negeri")%></option>
    Truly, you have a dizzying intellect.

Posting Permissions

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



Click Here to Expand Forum to Full Width