classic asp, when combobox option selected make db call [Answered]RSS

15 replies

Last post May 12, 2008 09:13 AM by tomkmvp

  • classic asp, when combobox option selected make db call

    May 04, 2008 11:39 PM|MyronCope|LINK

    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?

    thanks

  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 08:37 AM|tomkmvp|LINK

    You need to create a client-side script to handle the select control onchange event, which will then submit the form.
    http://msdn.microsoft.com/en-us/library/ms536912(VS.85).aspx

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 09:41 AM|MyronCope|LINK

    thanks again Tom, appreciate the help:

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

  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 10:17 AM|tomkmvp|LINK

    Yes.

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 10:42 AM|MyronCope|LINK

    thanks,

    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?

  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 11:05 AM|tomkmvp|LINK

    Is the vbscript client-side or server-side?

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 11:08 AM|MyronCope|LINK

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

  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 12:16 PM|tomkmvp|LINK

    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.

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 04:06 PM|MyronCope|LINK

    thanks again,

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

  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 04:17 PM|tomkmvp|LINK

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

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 05, 2008 08:35 PM|MyronCope|LINK

    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?

  • Re: classic asp, when combobox option selected make db call

    May 06, 2008 08:38 AM|tomkmvp|LINK

    Where would the recordset reside?

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 06, 2008 12:41 PM|MyronCope|LINK

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

     

    Also another thing:

    My combobox is like this:

     

    <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")%>">

    <%=rsStyle("Style_Name")%>

    </option>

    <%

    rsStyle.MoveNext

    Wend

    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;

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

  • Re: classic asp, when combobox option selected make db call

    May 06, 2008 02:37 PM|tomkmvp|LINK

    MyronCope

    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.

    MyronCope

    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?
    http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_settext

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: classic asp, when combobox option selected make db call

    May 10, 2008 08:18 PM|MyronCope|LINK

    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.

  • Re: classic asp, when combobox option selected make db call

    May 12, 2008 09:13 AM|tomkmvp|LINK

    If you don't want to reload the page, see these old articles on pre-AJAX DHTML data binding:
    http://msdn.microsoft.com/en-us/library/ms531388(vs.85).aspx
    (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.

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/