We help IT Professionals succeed at work.

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

858 Views
Last Modified: 2014-05-08
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.
Comment
Watch Question

Developer
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
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.
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
This solution  has some good info for getrows http:Q_28366983.html
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
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

Russell Scheinberg, MCSE Business IntelligenceSr. Business Intelligence Analyst

Author

Commented:
Thanks all for responding. This was exactly the answer I needed. Works perfectly! Saved me a lot of time. Thank you, Scott!
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.