By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,334 Members | 739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,334 IT Pros & Developers. It's quick & easy.

How to populate the dropdown values from another dropdown.

P: 24

I Have 2 dropdowns.The first dropdown contains main products which is from database table1.
If we select The one of dropdown value then the 2 second drop down should fill with all sub products of that main products from another table2.

Ex:: pulsor is the main product which is in 1 st dropdown
pulsor 150cc,pulsor 180cc ,pulsor 180cc are the sub prod s of pulsor.
when ever we select the pulsor on 1st dropdown it should disaply all sub models. same as per all models.

These two dropdowns should fill with from database only.

Nov 17 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 432
While its been awhile since ive done classic ASP (someone please correct me if I am wrong) I don't think you can capture a OnChange event in a drop down easily.

You might have to have to submit your form to the same page and add a querystring like &submittedMain=True ...then in your page check if submittedMain=True and if it is then you can populate your second drop down.

Assuming you know how to populate a record set with sql you would need sql that looks something like this

Select ProductKey,ProductName from Products where MainProductKey = " & SelectedMainProductKey & "

Then once you have that data in a record set use this:
Expand|Select|Wrap|Line Numbers
  1. <form>
  2. <select size="1" name="D1">
  3. <option VALUE="0" SELECTED>Select Sub Product</option><br>
  5. <%Do while not RS.eof
  6. Response.Write "<option VALUE=" & ProductKey & ">" & ProductName & "</option><br>"
  8. rs.movenext
  9. loop
  10. ' Exit the loop when reaching the end of the recordset
  11. 'If rs.EOF Then Exit For end if
  12. 'next
  13. 'end if%>
  14. </select>
  15. </form>
Nov 17 '09 #2

P: 24
Thanks ur reply.I got the code.Here it is....

strquery="Select * from products"
<select name="selprod" ID="dd1" onchange="reload(this.form);">
<option value="">Select prod</option>
<%if objrs.State <> 0 then objrs.Close
objrs.Open strquery,conn,3,3
While Not objrs.eof
Response.Write "<option value='" & prod_id & "' " & strSel & ">" &prodname& "</option>"

strquery1="Select * from sub_master where id="&id
<select name="selprod1" ID="dd2" >
<option value="">Select sub</option>

<%if objrs1.State <> 0 then objrs1.Close
objrs1.Open strquery1,conn,3,3
While Not objrs1.eof
Response.Write "<option value='" & prodid & "' " & strSel1 & ">" &prod_name& "</option>"
%> <!-- <option value="<%=prod_id%>" selected><%=prod_name%></option> -->
<% objrs1.moveNext

function reload(form)
var val=myform.selprod.options[myform.selprod.options.selectedIndex].value;
document.myform.action="index.asp?page=list"&id="+ val

Nov 18 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.