Picking a default value in dynamically filled comb

Results 1 to 3 of 3

Thread: Picking a default value in dynamically filled comb

  1. #1
    Join Date
    Dec 1969

    Default Picking a default value in dynamically filled comb

    I have a series of combo boxes ("Drop Down Menus") that are dynamically filled from a database A code sample is below. Is there anyway to pick a default value other than the first record in the recordset. The only way I can figure is to hard code the combobox to have a value that matches a record in the table. When I do this ofcourse, the value is show twice. Is there a better way?<BR><BR><BR><BR>============================== ===========<BR><BR>&#060;%<BR>Set PropChoices=Server.CreateObject("ADODB.Recordset") <BR>PropChoices.Open "queryValidPropTypes", "abcd"<BR>PropChoices.MoveFirst<BR>%&#062;<BR><BR> .....more html code....<BR><BR><BR><BR>&#060;select size="1" name="comboPropChoice"&#062;<BR>&#060;option selected&#062;Residential Single Dwelling&#060;/option&#062;<BR>&#060;% Do While Not PropChoices.EOF<BR>Response.Write "&#060;option value=&#039;"&PropChoices("Listing_Type")&"&#039;& #062;"<BR>Response.Write PropChoices("Listing_Type")&"&#060;/option&#062;"<BR>PropChoices.MoveNext<BR>Loop<BR>P ropChoices.Close<BR>Set PropChoices=nothing<BR>%&#062;<BR>&#060;/select&#062;<BR>

  2. #2
    Eddie Campbell Guest

    Default RE: Picking a default value in dynamically filled

    Call a subroutine to build the select option. Like this:<BR><BR>sub dropdown( rsName, ControlName, IdField, DisplayField, Selected)<BR>Response.Write "&#060;Select Name = " & ControlName & "&#062;"<BR>Do While Not rsName.Eof<BR> Response.Write "Option Value = " & rsName(IdField)<BR> If rsName(IdField) = Selected Then<BR> Response.Write " SELECTED"<BR> End If<BR> Response.Write "&#062;" & rsName(DisplayField)<BR> rsName.MoveNext<BR>Loop<BR>Response.Write "&#060;/Select&#062;"<BR><BR><BR>Then in you asp page call it like this. As you are using the same field for the Id and the display, you just put it in twice.<BR><BR>&#060;% dropdown PropChoices, "comboPropChoice", Listing_Type, Listing_Type, "Residential Single Dwelling" %&#062;

  3. #3
    Sandy Breon Guest

    Default RE: Picking a default value in dynamically filled

    I&#039;m not sure I totally understand what you&#039;re asking????<BR><BR>Do you know what the default value is before you populate the combo box?<BR><BR>If so, you will have to put a check inside your While loop to compare each field to your default value, and dynamically append the "selected" part of the tag if a match is found.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts