Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't choose required field in the form

Status
Not open for further replies.

volk125

Technical User
Jul 10, 2003
76
0
0
CA
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>
 
I think you wish to produce HTML that looks like this for the selected option.
Code:
<option value=2>Slow Curve</option>
<option value=23 selected>High Fast</option>
<option value=13>Changeup</option>

In other words, you simply write the keyword selected in the option, not selected = 23.

Code:
if tmp_method = rs("MethodID") then response.write(" selected")  end if
 
the html part is fine. it's condition that's not being met. I am not sure why. when it's going through the loop after it encounters the temp variable that matches the rs("method") value it's not inserting the html(selected). I just need it inserted in the line that matched the temp value that's been previously submitted via the form.
 
Are you comparing method to method or method to methodID?
 
methodID to methodID. because I assign the methodID to the tmp_method and then try to compare with rs("MethodID") from the recordset.
 
Technically rs("MethodID") is an object. tmp_method is probably a variant. Mostly VBScript handles this issue transparently. But you might try specifying the value property in the test.
Code:
If tmp_method = rs("MethodID").value Then

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top