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>
Re: session for list/menu problem
I wouldn't place code within the control elements
VB Code:
<select name ="negeri" class="text_normal" id="negeri">
<%
dim bSelected
set gnegeri = server.CreateObject("adodb.recordset")
gnegeri.open "select * from negeri" ,conn
if not gnegeri.eof then
for y=1 to gnegeri.recordcount
if gnegeri("id")=session("negeri") then
bSelected="selected"
else
bSelected=""
end if
%>
<option value="<%=gnegeri("id")%>" <%=bSelected%>>
<%=gnegeri("nama_negeri")%></option>