Results 1 to 12 of 12

Thread: drop down box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79

    drop down box

    Can anybody help me.

    1) I want to populate a drop down box from the result of a query.
    I already have a recordset with the values that I needed. Now how can I link the drop down box to the recordset.


    2) Then, I want to populate a second drop down box based on values selected from the first drop down box.


    Reggie

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    VB Code:
    1. Do While Not RS.EOF
    2. Response.Write "<option>" & rs.fields("Whatever") & "</option>"
    3. RS.MoveNext
    4. Loop
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79
    JoshT,

    This is the code I wrote but it is not populating my drop down box. I can see the box but the box is empty. I know I have 5 values in my recordset.
    What wrong with this piece of code:
    <%
    Response.Write "<br><Select Name=""cboSystem"" style=HEIGHT: 22px; WIDTH: 100px "&" >"

    Do While Not Rec.EOF
    Response.Write "<OPTION>" & Rec.Fields("LEGACY_SYSTEM_CD") & "</OPTION>"

    Rec.MoveNext
    loop

    Response.Write "</SELECT><br>"
    %>

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Look at the source code for the generated page and make sure there's the 5 <option> tags from your recordset. If not, it's a problem with the rs. (And the box will be empty until you pick something from the list, unless there's one and only one option tag with the selected attribute).
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79
    I have the same response.write code written outside the drop down box with a different do while loop and the results are

    20
    50
    64
    81
    83

    but my option box is blank. There is no values, nothing in there.
    So my recordset looks good, but its not populating the drop down box.

    Please help

    Reggie

  6. #6
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I bet its because your first loop moved the rs cursor to the end of the recordset and you never moved it back to the beginning (MoveFirst) of the recordset for the second loop. Make sure you're not opening it as Forward-Only.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79
    Sorry JoshT,

    That's exactly what was happening.
    Now, how can I populate the second combo box based on the value selected from the first combo box.
    What is the best way of doing this. Do I have to submit the form to itself or is there another way.

    Reggie

  8. #8
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Do you want the two combo boxes on the same page? You can do that with JavaScript (or some other client side script).

    If the two combo boxes are on different pages, then you can pull the value from the Request.Form object. Though I don't remember how to do that for multiple selection combo boxes.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79
    Actually, what I want is 3 combo boxes on one page. The first combo box should populate based on a query.
    The second combo box should be populated based on a query, for the value selected from combo box one.
    And the third combo box should be populated based on a query, for the value selected from combo box two.


    The reason why I want to do that way is, my first combo box is systems, second is division and third is products.
    So, if the user selects a value from combo one (systems), he should only see the divisions (in the second combo box) that are applicable to value selected in the first combo box.

    I hope I'm making some sense. I have this same application is VB, which works fine, but how can I write the same in ASP.

    Reggie

  10. #10
    Lively Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    115
    Since an ASP-page only "runs" when it's loaded you can't change contents of a page using ASP.
    The way you can do this is using JavaScript and loading all the different values into arrays. And using this choose what things to show in which combo boxes. As long as there isn't too many different values, this should be working just fine.

  11. #11
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Basically, you will create client side arrays using server side code and response.writes. With all the possible values. Another possibility is using client side XML, but be aware that using client side XML means IE only since you create an activeX instance of the XML parser.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79
    Thanks guys for all the input.

    I tried design time controls and script to populate, and all my drop down list boxes are working fine.

    This is the script I used:

    Sub thisPage_onenter()
    If thispage.firstEntered Then
    Recordset1.open
    End if
    End Sub


    Sub Listbox1_onchange()
    FillListbox2
    End Sub

    Sub Recordset1_ondatasetcomplete()
    FillListbox2
    End Sub


    Sub FillListbox2
    Listbox2.clear
    If Recordset2.isOpen() Then
    Recordset2.close
    End if
    sql="Select LEGACY_DIVISION_CD from pend_monthly_qinventory " & _
    "Where LEGACY_SYSTEM_CD = '" & Listbox1.getValue(Listbox1.selectedIndex) & "' " & _
    "group by LEGACY_DIVISION_CD "
    Recordset2.setSQLText(sql)
    Recordset2.open
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width