Spooky's Databases >
Modify the DRW>
Selected Listboxes
When a record is saved to your
database, it may be one of many pre-selected items a user had saved, or
it may be one of a specific list of items you have available to show a
user.
What ever it is, it is a selection of items you know and can list.
You all know what I mean by a list box,
it looks like this :
By default, you can't list the results
of the database region in a list box - a text box yes, but a list box -
no.
So, any use of a list box, usually means that your code will be on a
diet
To make list boxes appear selected when
loaded from a database, there are some steps we need to take.
The actual HTML code for that list
box looks like this :
The code that shows an option is
selected is, surprisingly, the part that says "selected"
So, "Option 1" is selected in the example above
The red code that is used to display
one value, is used to show the selected value in our list box.
Here we use a basic example that displays a company name. Your code may appear slightly different.
<%=FP_FieldVal(fp_rs,"Company")%>
Here is our list box code. You could
code this by hand, or you would use FrontPage.
To make this code show a a selected
value, we need to compare the database value with each of the <option>'s
that exist. In my example, we only have 2 options. In yours you may have
many. Each value however, needs to be checked.
Firstly, we save the actual database
value as a temporary variable.
This saves extra processing, as we now know what the value equals.
NOTE - this code replaces the line
<%=FP_FieldVal(fp_rs,"Company")%>
<%
DIM FpTemp
FpTemp = FP_FieldVal(fp_rs,"Company")
%>
Then, for each option, we say "If the
value of FpTemp = This options expected value, then write the word
selected"