I have a form with select option menu which I fill from database. Each option's value is the ID field and the actual display value is the description pulled from database. I am trying to do server side validation so once user hits submit I save the value in temporary variable then check it and if one or more fields in the form don't meet the requirements (Regular expressions) I display the form once again but values don't go away because I saved them in temporary variables and now displaying them again. But the Option field that's filled from database resets every time. There is an attribute "SELECTED = value" which allows to select which one I want to display as default. So once submitted I know which value has to be displayed in the Option field. But I can't seem to get to display. I tried an if statement where I tried to match the TMP_FIELDVALUE with RS("IDVALUE") and based on that display the proper value but it doesn't work. Desperately need help...
Here's the code...
<td>Contact Method:</td><td>
<!--#include file="dbconn.asp"-->
<%
strSQL = "SELECT MethodID, Method, Description FROM DB.dbo.ContactMethods "
rs.Open strSQL,Conn,adOpenForwardOnly
Response.write("<select name='Method' id='Method'>")
Response.write("<option value='-=Select Contact Method=-'>-=Select Contact Method=-</option>")
if not rs.EOF = true then
do while not rs.EOF = true %>
<option value=
<%
response.write(rs("MethodID"))
*Comment: this line below is the one I'm trying to insert the SELECTED = Value piece with. And supposedly while going through the values it should insert the attribute because it matches the value pulled from database.
'if tmp_method = rs("MethodID") then response.write(" selected = '" & rs("MethodID") & "'") end if
%>
>
<% response.write(rs("Method"))%>
</option>
<%
rs.MoveNext
loop
%></select><%
rs.close
conn.close
else
response.write("Did not connect!")
end if
response.write(" Tmp=" & tmp_method)
%> </td>
<td><% If badValue AND tmp_method = "-=Select Contact Method=-" Then Response.Write("* required") %></td>
Here's the code...
<td>Contact Method:</td><td>
<!--#include file="dbconn.asp"-->
<%
strSQL = "SELECT MethodID, Method, Description FROM DB.dbo.ContactMethods "
rs.Open strSQL,Conn,adOpenForwardOnly
Response.write("<select name='Method' id='Method'>")
Response.write("<option value='-=Select Contact Method=-'>-=Select Contact Method=-</option>")
if not rs.EOF = true then
do while not rs.EOF = true %>
<option value=
<%
response.write(rs("MethodID"))
*Comment: this line below is the one I'm trying to insert the SELECTED = Value piece with. And supposedly while going through the values it should insert the attribute because it matches the value pulled from database.
'if tmp_method = rs("MethodID") then response.write(" selected = '" & rs("MethodID") & "'") end if
%>
>
<% response.write(rs("Method"))%>
</option>
<%
rs.MoveNext
loop
%></select><%
rs.close
conn.close
else
response.write("Did not connect!")
end if
response.write(" Tmp=" & tmp_method)
%> </td>
<td><% If badValue AND tmp_method = "-=Select Contact Method=-" Then Response.Write("* required") %></td>