473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to populate the dropdown values from another dropdown.

24
Hii..

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.

Thanks
Nov 17 '09 #1
2 10572
jeffstl
432 Expert 256MB
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>
  4.  
  5. <%Do while not RS.eof
  6. Response.Write "<option VALUE=" & ProductKey & ">" & ProductName & "</option><br>"
  7.  
  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
chinni1
24
Hiii...
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
prod_id=objrs(0)
prodname=objrs(1)
Response.Write "<option value='" & prod_id & "' " & strSel & ">" &prodname& "</option>"
objrs.moveNext
Wend
</select>

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
prodid=objrs1(0)
prod_name=objrs1(2)
Response.Write "<option value='" & prodid & "' " & strSel1 & ">" &prod_name& "</option>"
%> <!-- <option value="<%=prod_id%>" selected><%=prod_name%></option> -->
<% objrs1.moveNext
Wend
</select>


<SCRIPT LANGUAGE="JavaScript">
function reload(form)
{
var val=myform.selprod.options[myform.selprod.options.selectedIndex].value;
document.myform.method="Post";
document.myform.action="index.asp?page=list"&id="+ val
document.myform.submit();
}

Thanks...
Nov 18 '09 #3

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

Similar topics

20
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer...
0
by: Marc Miller | last post by:
Hi to all, (I apologize that I posted this in dotnet.languages.vb.controls, but I NEED and answer quickly, please) I have an 'employees' datagrid which contains company numbers as labels....
3
by: Seelan | last post by:
Hey Guys, I have read a table from SQL Server to a Dataset called ds. Now I want to list the items of one column to a DropDown List...I can do this perfectly but i want ht e list to contain...
2
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I...
1
by: oj | last post by:
Could anyone provide some approaches that are used to cache dropdown list control values to share globally beteween all users? Currently, each time a page is loaded all the dropdown values for each...
11
by: abctech | last post by:
Hi, I am developing a webapplication using Javascript,JSP,Servlets. I have 2 dropdown lists in my form, the first one is autopopulated on form load , I have written this code in Jsp and its...
0
by: Padma Athimoolam | last post by:
Hi, I am new to VB and XML.I want to populate XML Values in Excel Sheet.My Sample XML is <?xml version="1.0" encoding="UTF-8" ?> - <workbook> - <worksheet name="Scorecard_KTC_MW"> <cell...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
0
by: jeccinta jeccinta | last post by:
Hi am using a grid view.I have 2 drop down lists inside gridview.one dropdownlist1 fetches country names.Based on that i should get state names in another dropdown list2.how to write code for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.