Gwen21
asked on
Combo Boxes working together.
I have a drop down box that pulls from a table a group of suppliers. What I am trying to do is once the supplier is chosen it then lists in a separate drop down box lists out all the projects for that supplier.
Here is what I have so far :
Combo box # 1 :
Major Customer :
<select name="sel_Major" onchange="fillInfo(documen t.form1.se l_Major.va lue);" class="cls10px">
<option selected></option>
<%
strSQL = " SELECT CustomerID, Customer_Name"
strSQL = strSQL & " FROM Customer_Index"
strSQL = strSQL & " ORDER BY Customer_Name"
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
%>
<option value="<%=objRS("CustomerI D")%>" class="cls10px" <%If objRS("CustomerID") = strCustomerID Then%>selected<%End If%>><%=objRS("Customer_Na me")%></op tion>
<%
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
%>
</select>
Combo Box #2 :
Project Number:
<select name="sel_project_num" onchange="fillInfo2(docume nt.form1.s el_project _num.value );" class="cls10px">
<option selected></option>
<%
strSQL = "SELECT Customer_Index.CustomerID, Customer_Index.Customer_Na me, Project_Index.ProjectID, Project_Index.CustomerID AS CustID, Project_Index.Project_Numb er, Project_Index.Description "
strSQL = strSQL & " FROM Customer_Index INNER JOIN "
strSQL = strSQL & " Project_Index ON Customer_Index.CustomerID ='"&strID&"' AND Customer_Index.CustomerID = '"&strCustomerID&"'"
strSQL = strSQL & "ORDER BY Customer_Index.Customer_Na me"
Set objRS2 = objConn.Execute(strSQL)
While Not objRS2.EOF
%>
<option value="<%=objRS2("Project_ Number")%> " class="cls10px"<%If objRS2("Project_Number") = strProjectNumber Then%>selected<%End If%>><%=objRS2("Project_Nu mber")%></ option>
<%
objRS2.MoveNext
Wend
objRS2.Close
Set objRS2 = Nothing
%>
</select>
How do I get them to work together? Any advice would be great. Thanks in advance.
Gwen
Here is what I have so far :
Combo box # 1 :
Major Customer :
<select name="sel_Major" onchange="fillInfo(documen
<option selected></option>
<%
strSQL = " SELECT CustomerID, Customer_Name"
strSQL = strSQL & " FROM Customer_Index"
strSQL = strSQL & " ORDER BY Customer_Name"
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
%>
<option value="<%=objRS("CustomerI
<%
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
%>
</select>
Combo Box #2 :
Project Number:
<select name="sel_project_num" onchange="fillInfo2(docume
<option selected></option>
<%
strSQL = "SELECT Customer_Index.CustomerID,
strSQL = strSQL & " FROM Customer_Index INNER JOIN "
strSQL = strSQL & " Project_Index ON Customer_Index.CustomerID ='"&strID&"' AND Customer_Index.CustomerID = '"&strCustomerID&"'"
strSQL = strSQL & "ORDER BY Customer_Index.Customer_Na
Set objRS2 = objConn.Execute(strSQL)
While Not objRS2.EOF
%>
<option value="<%=objRS2("Project_
<%
objRS2.MoveNext
Wend
objRS2.Close
Set objRS2 = Nothing
%>
</select>
How do I get them to work together? Any advice would be great. Thanks in advance.
Gwen
put this javascript in the head section of your document
<script language="javascript">
<!--
function setFormAction(url){
document.forms[0].action=u rl;
document.forms[0].submit() ;
}
//-->
</script>
Then use the code below.
Before using it, replace "index.asp with your page
Major Customer :
<%
strSQL = " SELECT CustomerID, Customer_Name"
strSQL = strSQL & " FROM Customer_Index"
strSQL = strSQL & " ORDER BY Customer_Name"
%>
<select name="sel_Major" onchange="setFormAction("i ndex.asp") ;" class="cls10px">
<option selected></option>
<%
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
%>
<option value="<%=objRS("CustomerI D")%>" class="cls10px" <%If objRS("CustomerID") = strCustomerID Then%>selected<%End If%>><%=objRS("Customer_Na me")%></op tion>
<%
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
%>
</select>
Combo Box #2 :
Project Number:
<%
Dim strCustomerID
strCustomerID=request.form ("sel_Majo r")
strSQL = "SELECT Project_Index.ProjectID, Project_Index.CustomerID, Project_Index.Project_Numb er, Project_Index.Description "
strSQL = strSQL & " FROM Project_Index "
strSQL = strSQL & " WHERE Project_Index.CustomerID = '"&strCustomerID&"'"
%>
<select name="sel_project_num" onchange="fillInfo2(docume nt.form1.s el_project _num.value );" class="cls10px">
<option selected></option>
<%
Set objRS2 = objConn.Execute(strSQL)
While Not objRS2.EOF
%>
<option value="<%=objRS2("Project_ Number")%> " class="cls10px"<%If objRS2("Project_Number") = strProjectNumber Then%>selected<%End If%>><%=objRS2("Project_Nu mber")%></ option>
<%
objRS2.MoveNext
Wend
objRS2.Close
Set objRS2 = Nothing
%>
</select>
<script language="javascript">
<!--
function setFormAction(url){
document.forms[0].action=u
document.forms[0].submit()
}
//-->
</script>
Then use the code below.
Before using it, replace "index.asp with your page
Major Customer :
<%
strSQL = " SELECT CustomerID, Customer_Name"
strSQL = strSQL & " FROM Customer_Index"
strSQL = strSQL & " ORDER BY Customer_Name"
%>
<select name="sel_Major" onchange="setFormAction("i
<option selected></option>
<%
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
%>
<option value="<%=objRS("CustomerI
<%
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
%>
</select>
Combo Box #2 :
Project Number:
<%
Dim strCustomerID
strCustomerID=request.form
strSQL = "SELECT Project_Index.ProjectID, Project_Index.CustomerID, Project_Index.Project_Numb
strSQL = strSQL & " FROM Project_Index "
strSQL = strSQL & " WHERE Project_Index.CustomerID = '"&strCustomerID&"'"
%>
<select name="sel_project_num" onchange="fillInfo2(docume
<option selected></option>
<%
Set objRS2 = objConn.Execute(strSQL)
While Not objRS2.EOF
%>
<option value="<%=objRS2("Project_
<%
objRS2.MoveNext
Wend
objRS2.Close
Set objRS2 = Nothing
%>
</select>
ASKER
I think YZlat’s code is more what I am looking for. But still struggling to get the value from Combo one to the sql statement in combo two.
make sure the form is submitted when the value of first combo box is changed, and then
use request.form("sel_Major")
use request.form("sel_Major")
ASKER
Ok that is where the probelm seems to be, the form is not submitting.
ok, are your select boxes on the form or no?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YZlat Thanks so much. Putting document.forms[0].submit() ; in the onchange of the <select> made it work.
r u looking for something like this
<script language=javascript>
function fillInfo(val)
{
location.href="samepage.as
}
</script>
<body>
<td class=tdr width=28%>Major Customer:
<select name="sel_Major" onchange="fillInfo(documen
<option selected></option>
<%
strSQL = " SELECT CustomerID, Customer_Name"
strSQL = strSQL & " FROM Customer_Index"
strSQL = strSQL & " ORDER BY Customer_Name"
Set objRS = objConn.Execute(strSQL)
While Not objRS.EOF
%>
<option value=<%=objRS("CustomerID
<%
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
%>
</select>
</td>
<td class=tdr width=27%>Project Number:
<select name="sel_project_num" class="cls10px">
<option selected></option>
<%
strSQL = "SELECT Customer_Index.CustomerID,
strSQL = strSQL & " FROM Customer_Index INNER JOIN "
strSQL = strSQL & " Project_Index ON Customer_Index.CustomerID ='"&Project_Index.Customer
strSQL = strSQL & "ORDER BY Customer_Index.Customer_Na
Set objRS2 = objConn.Execute(strSQL)
While Not objRS2.EOF
%>
<option value=<%=objRS2("Project_N
<%
objRS2.MoveNext
Wend
objRS2.Close
Set objRS2 = Nothing
%>
</select>
</td>
</body>