navigation
Thomas Brunt's OutFront Hosting
 
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Microsoft MVP
 

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 :

<select size="1" name="D1">
<option>None</option>

<option selected value="Option 1">Option 1</option>
<option>Option 2</option>
</select>

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.

<select size="1" name="Company">
<option>None</option>
<option value="Company 1">Company 1</option>
<option value="Company 2">Company 2</option>
</select>

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"

<select size="1" name="Company">
<option>None</option>
<option value="Company 1"
<%If FpTemp = "Company 1" then response.write "selected"%>>Company 1</option>
<option value="Company 2"
<%If FpTemp = "Company 2" then response.write "selected"%>>Company 2</option>
</select>

If no selection exists, then a value of "none" will be displayed.



 


Microsoft Corporation in no way endorses or is affiliated with "OutFront." 
OutFront is published and edited by Thomas Brunt
440 Great Circle Dr., St. Matthews, SC 29135.  803-655-6151
© 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 All Rights Reserved
Click here to view our privacy statement.