classic asp, when combobox option selected make db call RRS feed

  • Question

  • User-1210839387 posted

    I have a classic asp combobox and when an option is selected on it i need to fire javascript that will then call a vb script function that will query a database to return values to fill combobox number 2.

    The vbscript will create the sql query and query the db, return the recordset and then bind to the second combo box.  the thing that is tricky is getting the vbscript to be called from the combobox selection, not sure how to do this.

    EX:  make a selection on Combo1 and then query database based on the value selected and use the records returned from the database to populate Combo2.

    Does anyone have any code samples of this?  Can this be done or do I have to use some other scripting language?


    Sunday, May 4, 2008 11:39 PM


All replies

  • User-823196590 posted

    You need to create a client-side script to handle the select control onchange event, which will then submit the form.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, May 5, 2008 8:37 AM
  • User-1210839387 posted

    thanks again Tom, appreciate the help:

    so you are saying that I will need to submit the form, load the page again.

    Monday, May 5, 2008 9:41 AM
  • User-823196590 posted


    Monday, May 5, 2008 10:17 AM
  • User-1210839387 posted


    is there anyway to fire javascript when user selects an option from the combobox and then have that javascript function call a vbscript function which will query the database based on the combobox selection?

    Monday, May 5, 2008 10:42 AM
  • User-823196590 posted

    Is the vbscript client-side or server-side?

    Monday, May 5, 2008 11:05 AM
  • User-1210839387 posted

    the vbscript is in the asp page, so i guess that would client-side.

    Monday, May 5, 2008 11:08 AM
  • User-823196590 posted

    There is some old remote data technology but I think your best bet is to submit the form which will then reload the ASP and run the server-side code.

    Monday, May 5, 2008 12:16 PM
  • User-1210839387 posted

    thanks again,

    would it be possible to use AJAX with Classic ASP to hit the db?

    Monday, May 5, 2008 4:06 PM
  • User-823196590 posted

    Maybe - I only have AJAX experience with ASP.NET though.  You would have to research that.

    Monday, May 5, 2008 4:17 PM
  • User-1210839387 posted

    what if I create a second recordset on initial pageload and then when you select the first combobox then bind the filterered second recordset to the second combobox.

    Can you bind a recordset to a combobox on a javascript call?

    Monday, May 5, 2008 8:35 PM
  • User-823196590 posted

    Where would the recordset reside?

    Tuesday, May 6, 2008 8:38 AM
  • User-1210839387 posted

    The recordset is on the same asp page as the comboboxes.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Also another thing:

    My combobox is like this:

    <o:p> </o:p><o:p>

    <select onchange="javascript:__StyleChanged()" name="PopulateStyle" size="1" style="width:400px">

    <option value="0~">No Style Selected</option>


    While not rsStyle.EOF


    <option value="<%=rsStyle("Style_Name")%>">






    If rsStyle.State = adStateOpen Then rsStyle.Close

    Set rsStyle= nothing



    You see that I display the Style_name and the value is the style_name.

    I want to change this so the value will be a StyleID from the recordset and I still want to display the Style_Name to the user, but after this I need to know how to get both the Style_Name and the Style_Id.

    I will use the selected STyle_Id to filter the second recordset and then I want to bind this recordset to the second combobox.

    I have a Javascript function now that gets the .value which is now the Style_Name so I know if I change the value to be StyleID then it will get that, so I know how to change that.

    But I also need to know the javascript syntax to get the style_name or selected value, what is the syntax for that?  Is it something like option[s].selected?

    What I have now is this, this gets the value.  How do you get the selected text? (it must be something similar to this):

                var vl;<o:p></o:p>

                vl = document.frmSend.PopulateStyle.options[s].value;

    Tuesday, May 6, 2008 12:41 PM
  • User-823196590 posted

    The recordset is on the same asp page as the comboboxes.
    I think you're getting client-side and server-side concepts all mixed up.

    But I also need to know the javascript syntax to get the style_name or selected value, what is the syntax for that?  Is it something like option[s].selected?

    Tuesday, May 6, 2008 2:37 PM
  • User-1210839387 posted

    my last post was a side question, but I still want to find out how to query the database on selection of a combobox without refreshing the page, i know this is essentially some form of Ajax.

    I know how to make the javscript fire when you change a combobox.

    I know how to query a database from an asp page.

    I just need to know the missing link in the middle, making the connection between the javascript and the server.

    Saturday, May 10, 2008 8:18 PM
  • User-823196590 posted

    If you don't want to reload the page, see these old articles on pre-AJAX DHTML data binding:
    (fwiw, this pretty much takes ASP out of the picture)

    If you can reload the page, then you simply have the javascript fire a form post, then in the ASP look at the new combobox value that was submitted, run a new query based on that value, and build the second combobox with this new data.

    Monday, May 12, 2008 9:13 AM