Link to home
Start Free TrialLog in
Avatar of Russell Scheinberg, MCSE Business Intelligence
Russell Scheinberg, MCSE Business IntelligenceFlag for United States of America

asked on

How do I load a dynamic array from a SQL query into multiple pull down inputs on a classic ASP page?

Greetings all,

I am trying to figure out the best way to load the same dynamically generated (from a SQL server query) list into multiple pull down (select) input form objects on a classic ASP page. I think it might require a combination of vbscript  (to query the database) and javascript (to hold and display the pull down).  The sql query would look like this:

SELECT ListID, Symbol FROM Deals WHERE Active = 1

This would give me an array of unkown rows with ListID and Symbol pairs.

I then have a form with multiple (20) rows and each row needs to have the values of this array loaded into a pull down for one of the entries.

<select name="selDeal" id="selDeal">
<option value="ListID value from array">Symbol value from array</option>
</select>

I began to work on this but realized there might be a simple way to do it and I might not have to re-invent the wheel to do it if someone has already dealt with this scenario.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You will have to create a drop down control for each row and each with different name. Imagine this. On each row you have selected a different value from the list, which you will have then to post to the server. You need to be able to come up wit h the values for each row so basically the name of the drop down object will have to reflect or to be related somehow to the row, like a unique id/value per row.
This solution  has some good info for getrows http:Q_28366983.html
I'm not sure I totally understand what you need, but if you need multiple dropdowns where one is dependent on the other, I like to use jquery chained http://www.appelsiini.net/projects/chained
 
The set up is easy. From the sample on their page, you can see taht the value of the first select is equal to the class of the second.  When you select the first one, then only the choices with the matching class will be available in the 2nd.  You can generate the options just as I sampled originally.  
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.chained.min.js"></script>
<select id="mark" name="mark">
  <option value="">--</option>
  <option value="bmw">BMW</option>
  <option value="audi">Audi</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="bmw">3 series</option>
  <option value="series-5" class="bmw">5 series</option>
  <option value="series-6" class="bmw">6 series</option>
  <option value="a3" class="audi">A3</option>
  <option value="a4" class="audi">A4</option>
  <option value="a5" class="audi">A5</option>
</select>

Open in new window

Avatar of Russell Scheinberg, MCSE Business Intelligence

ASKER

Thanks all for responding. This was exactly the answer I needed. Works perfectly! Saved me a lot of time. Thank you, Scott!
Glad it worked!  

Sometimes for larger arrays, I like to assign variables to help me remember what goes where instead of 0,1,2...

<%
For r = LBound(arrData, 2) To UBound(arrData, 2)
    ListID     = arrData(0,r)
    Symbol = arrData(1,r)

%>
    <option value="<%=ListID%>"><%=Symbol%></option>	
<%
next
%>

Open in new window