[thelist] ASP Select Form not auto-selecting

Ken Schaefer ken at adOpenStatic.com
Thu Sep 25 21:04:12 CDT 2003


One is a variant, and the other is something that's being returned by a
method of a recordset.

Try:


If CInt(request.form("Manager")) = CInt(Managers.fields.item("RepID").value)
then
    Response.Write("Values are equal")
Else
    Response.Write("Values are not equal")
End If

Also, here's a routine that you can use for writing out select lists, so you
can have a single line of code in your html section, rather than that mess
of inline code. Stick the routine in an include file.


'------------------------------------------------------------
' WriteFormSelectList
'------------------------------------------------------------ 
' Returns HTML for a <select> element
' Accepts strName as string
' Accepts strID as string
' Accepts strHTMLAttributes as string - literal text for any other HTML
attributes
' Accepts form option elements as array
' Accepts array format as integer: 0 = rows/cols, 1 = cols/rows (eg from
getRows)
' Accepts optional text for first <option></option> tag
' Accepts strSelectedValue as option to be selected
'------------------------------------------------------------
Function WriteFormSelectList( _
 ByVal strName, _
 ByVal strID, _
 ByVal strHTMLAttributes, _
 ByVal arrOptions, _
 ByVal intArrayFormat, _
 ByVal strFirstOption, _
 ByVal strSelectedValue _
 )

 Dim i   ' array 1st dimension counter

 If not isArray(arrOptions) then
  Exit Function
 End If

 WriteFormSelectList = "<select name=""" & strName & """ ID=""" & strID &
""""

 If Len(strHTMLAttributes & "") > 0 then
  WriteFormSelectList = WriteFormSelectList & " " & strHTMLAttributes & """"
 End If

 WriteFormSelectList = WriteFormSelectList & ">" & vbCrLf

 If Len(strFirstOption) > 0 then
  WriteFormSelectList = WriteFormSelectList & strFirstOption & vbCrLf
 End If

 If intArrayFormat = 0 then
  For i = 0 to Ubound(arrOptions, 1)
   WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(i,0) & """>" & arrOptions(i,1) & "</option>" & vbCrLf
  Next
 Else
  For i = 0 to Ubound(arrOptions, 2)
   WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(0,i) & """>" & arrOptions(1,i) & "</option>" & vbCrLf
  Next
 End If

 WriteFormSelectList = WriteFormSelectList & "</select>" & vbCrLf

 If Len(strSelectedValue & "") > 0 then
  WriteFormSelectList = Replace(WriteFormSelectList, "value=""" &
strSelectedValue & """>", "value=""" & strSelectedValue & """ selected>")
 End If

End Function
'------------------------------------------------------------
' --- WriteFormSelectList
'------------------------------------------------------------

----- Original Message ----- 
From: "Rob Smith" <rob.smith at THERMON.com>
To: "Thelist (E-mail)" <thelist at lists.evolt.org>
Sent: Friday, September 26, 2003 7:06 AM
Subject: [thelist] ASP Select Form not auto-selecting


: Hi list
:
: If you've ever created a form that submits to itself for form validation
: before proceeding on, this is for you. Mine has a drop-down menu that, if
: there's something wrong with the form, would auto select whatever WAS
: originally selected:
:
: <select name="Manager">
:  <option value=""></option>
:  <%
:  while not Managers.eof
:   response.write("<option value=""" & Managers.fields.item("RepID").value)
:   if request.form("Manager") = Managers.fields.item("RepID").value then
:    response.write(" selected ")
:   end if
:   response.write(""">" & Managers.fields.item("RepName").value &
: "</option>")
:   Managers.movenext
:  wend
:  %>
: </select>
:
: In this example the forms RepID is 92503 (today's date). After selecting
: this particular form I printed out:
:
: response.write request.form("Manager") & " "
: Managers.fields.item("RepID").value
:
: Low and behold my output is:
: 92503 92503
:
: Yet... the test to compare these two to enable the "selected" feature,
: fails.
:
: Does anyone have an explanation?



More information about the thelist mailing list