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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if objRS("field") = Request.Form("key") never evaluates to t

Status
Not open for further replies.

stephenmbell

IS-IT--Management
Jan 7, 2004
109
US
I am populating a combo box with values from a recordset. My select box load fine, receives the proper data. I am trying to submit to the form any number in the select box and post to itself with the proper value selected. My condition never evaluates the if..it is always the else..

why?

Thanks

Code:
<select name="cboShop" id="cboShop"   onchange="document.form.submit()">
<%
Dim rsShops, strSQL
			
strSQL = "select num from shops order by num asc"
set rsShops = fnGetRecordset(strSQL)
Do Until rsShops.EOF
  If rsShops.Fields("num").value = Request.Form("cboShop") Then		    
  '  Response.write("S rec: " & rsShops("num").value & " url: " & Request.Form("cboShop") & vbcrlf)
    Response.Write("<option selected>" & rsShops("num").value & "</option>")
  Else
    'Response.write("rec: " & rsShops("num").value & " url: " & Request.Form("cboShop") & vbcrlf)
    Response.Write("<option>" & rsShops("num").value & "</option>")
  End If			  
  rsShops.movenext
Loop
rsShops.Close
set rsShops = Nothing
%>
</select>
 
Try this...

Code:
If [!]Trim([/!]rsShops.Fields("num").value[!])[/!] = [!]Trim([/!]Request.Form("cboShop")[!])[/!] Then

-George

"the screen with the little boxes in the window." - Moron
 
Only character strings come from the request buffer but the ADO recordset can, and often does, contain numeric datatypes or nulls.

You can concatinate an empty string onto any database datatype and ASP will automatically cast that value as a string. This allows you to compare apples to apples.
[tt]
if objRS("field") & "" = Request.Form("key") then[/tt]

This is always a good idea unless you have a special situation where you actually need to distinguish a null from an empty string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top