|
 |
asp_web_howto thread: Drop Down List Box w/ data
Message #1 by "Rich" <ripatt@h...> on Fri, 26 Oct 2001 07:13:32 -0400
|
|
Here is my problem. . . I have a drop down box w/ selections.
When the page is loaded the box displays the value from a database field
plus values that were hard coded into it. Like this:
<SELECT name=DataField onChange="jumpMenu">
<%
sField = rsLO("Field")
if sField <> "" then
response.write "<option value=" & Field & " selected>" & Field&
"</option>"
end if
%>
<OPTION value=AdminRedir.asp?FrmName=theForm>Hard Coded Value</OPTION>
<OPTION value=. . .etc. . . . .
When i do it this way, it has all the hard coded data plus the database
table field data. the field data matches one of the hard coded value,
so there is two selections of the same thing. How can i just make the drop
down list box select the database field instead of adding it on top
of the other values. Any help would be greatly appreciated.
Message #2 by "Coffey, Dana" <dcoffey@B...> on Fri, 26 Oct 2001 06:21:34 -0700
|
|
You could store all your hardcoded values in an array, and then when you go
to write out the database field data, loop through the array comparing the
array values to the field value.
print flag = "on"
for each array_item in MY_Array
if myfield = array_item then
printflag = "off"
end if
next
Then only print the database field info if the printflag is set to "off"
hth,
d
-----Original Message-----
From: Rich [mailto:ripatt@h...]
Sent: Friday, October 26, 2001 7:14 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Drop Down List Box w/ data
Here is my problem. . . I have a drop down box w/ selections.
When the page is loaded the box displays the value from a database field
plus values that were hard coded into it. Like this:
<SELECT name=DataField onChange="jumpMenu">
<%
sField = rsLO("Field")
if sField <> "" then
response.write "<option value=" & Field & " selected>" & Field&
"</option>"
end if
%>
<OPTION value=AdminRedir.asp?FrmName=theForm>Hard Coded Value</OPTION>
<OPTION value=. . .etc. . . . .
When i do it this way, it has all the hard coded data plus the database
table field data. the field data matches one of the hard coded value,
so there is two selections of the same thing. How can i just make the drop
down list box select the database field instead of adding it on top
of the other values. Any help would be greatly appreciated.
Message #3 by "Ken Schaefer" <ken@a...> on Sat, 27 Oct 2001 19:58:18 +1000
|
|
You create an array of elements. You then use a function like the following
to create a string that contains the necessary HTML. You call the function
like this:
<%=WriteFormSelectList("Name", "ID", "OtherHTML", arrOfElements,
arrayFormat, "OptionalFirstElement", varSelectedValue)%>
eg
<%=WriteFormSelectlist("cboTest", "1", "", arrTest, 0, "", 1)%>
watch for wrapping!
'------------------------------------------------------------
' 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 strFirstOption as first <option></option> tags
' 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
'------------------------------------------------------------
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Rich" <ripatt@h...>
Newsgroups: asp_web_howto
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, October 26, 2001 9:13 PM
Subject: [asp_web_howto] Drop Down List Box w/ data
: Here is my problem. . . I have a drop down box w/ selections.
: When the page is loaded the box displays the value from a database field
: plus values that were hard coded into it. Like this:
:
: <SELECT name=DataField onChange="jumpMenu">
: <%
: sField = rsLO("Field")
: if sField <> "" then
: response.write "<option value=" & Field & " selected>" & Field&
: "</option>"
: end if
: %>
: <OPTION value=AdminRedir.asp?FrmName=theForm>Hard Coded Value</OPTION>
: <OPTION value=. . .etc. . . . .
:
:
: When i do it this way, it has all the hard coded data plus the database
: table field data. the field data matches one of the hard coded value,
: so there is two selections of the same thing. How can i just make the drop
: down list box select the database field instead of adding it on top
: of the other values. Any help would be greatly appreciated.
:
:
:
$subst('Email.Unsub')
|
|
 |