Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Populating another drop down list, based on the selection from another drop down list


Message #1 by "Ray Kano" <rkano@a...> on Mon, 26 Aug 2002 19:31:09
Here is my code below, I query the database to get me a recordset...the 
company name populates my first drop. So based on that selection, I want 
to automatically populate the address and a contact person drop down. 
There may be more that one contact per company, so I want that to be a 
drop down as well. You will see my reference to this drop down as I have 
put in a comment in CAPS where my code starts: 

<%@language=VBScript%>
<%
Dim objConn, strSQL, objRS, lngCol
Set objConn = Server.CreateObject("ADODB.Connection")
ObjConn.ConnectionString = "DSN=RMA;UID=sa;PWD=1"
objConn.Open 

strSQL = "select rmanum from RMA order by RMANum desc " 
Set objRS=objConn.Execute(strSQL)

strSQL1 = "SELECT distinct company, contact, title, phone1, address1" &_
" FROM contact1 where company > ' ' order by company " 
Set objRS1=objConn.Execute(strSQL1)

%>




<html>

<head>
<title>New Page 1</title>
</head>

<body bgcolor="#FFFFFF">
<a href="/WebApps/RMA/homepage.asp"><p><img border="0" 
src="Stuff/rma_online.gif"></p></a>

<p align="center"><b><font face="Arial Black" color="#0000FF"><i>A Test 
Form Page for RMA's</i></font></b></p>
<form method=post action="addnewrma.asp" name=newrma>
<p align="center">&nbsp;</p>
<p align="left">  &nbsp;  <p>
<table border="1" width="100%" bordercolor="#FFFFFF" height="183">
  <tr>
    <td width="15%" height="19">
      <b><font color="#800080">Today's Date :&nbsp; </font></b> </td>
    <td width="51%" height="19"><%=Mydate%></td>
  </tr>
  <tr>
    <td width="15%" height="22">
      <p align="left"><b><font color="#800080">RMA Number :</font></b></td>
    <td width="51%" height="22"><input type="text" size=10 value="<%= 
NewMaxRma %>" name="rmanum" id="1" tabindex="1"></td>
  </tr>


<!-- HERE IS WHERE MY FIRST DROP DOWN STARTS -->
  
  <tr>
    <td width="15%" height="23">
      <p align="left"><b><font color="#800080">Company 
Name&nbsp; :</font></b></td>
    <td width="51%" height="23">
    

<Select Name="Customer" size="1"
  onchange="alert(options[this.selectedIndex].value)">
    
<BR>

	<%While Not objRS1.EOF%>

<option value="<%= objRS1("company") %>"><%= objRS1("company") %></option>

<%
objRS1.MoveNext
Wend

%>
</Select>




    </td>
  </tr>
  
  <tr>
    <td width="15%" height="23">
      <p align="left"><b><font color="#800080">Address :</font></b></td>
    <td width="51%" height="23"><input type="text" size=50 value="" 
name="address1" id="3" tabindex="3"></td>
  </tr>
  <tr>
    <td width="15%" height="23">
      <p align="left"><b><font color="#800080">Contact 
Person :&nbsp;</font></b></td>
    <td width="51%" height="23"><input type="text" size=50 value="" 
name="contact" id="4" tabindex="4"></td>
  </tr>
  <tr>
    <td width="15%" height="38"><b><font color="#800080">Telephone 
Number :</font></b></td>
    <td width="51%" height="38"><input type="text" size=15 value="" 
name="telnumber" id="5" tabindex="5"></td>
  </tr>
  <tr>
    <td width="15%" height="37"><b><font color="#800080">Serial 
Number :</font></b></td>
    <td width="51%" height="37"><input type="text" size=15 value="" 
name="sernum" id="50" tabindex="6"></td>
  </tr>
</table>
<p align="left"><b><font color="#800080">Product 
Description :</font></b></p>
<p align="left"><textarea rows="3" name="proddesc" cols="60" id="6" 
tabindex="7"></textarea></p>
<p align="left"><b><font color="#800080">Problem :</font></b></p>
<p align="left"><textarea rows="3" name="Problem" cols="60" id="60" 
tabindex="8"></textarea></p>
<table border="1" width="505" bordercolor="#FFFFFF">
  <tr>
    <td width="135"><b><font color="#800080">Date Received :</font> </b> 
</td>
    <td width="80"> <input type="text" size=10 value="" name="daterec" 
id="7" tabindex="9"></td>
    <td width="151"><b><font color="#800080">&nbsp;&nbsp;&nbsp;&nbsp; Date 
Returned :</font> </b> </td>
    <td width="111"> <input type="text" size=10 value="" name="dateret" 
id="8" tabindex="10"></td>
  </tr>
</table>
<p align="left"><b><font color="#800080">&nbsp;Work Performed :</font></b> 
</p>
<p align="left">&nbsp;<textarea rows="3" name="workperf" cols="60" id="9" 
tabindex="11"></textarea></p>
<p align="left"><b><font color="#800080">&nbsp;Parts 
Needed :</font></b></p>
<p align="left">&nbsp;<textarea rows="3" name="partneed" cols="60" id="10" 
tabindex="12"></textarea></p>
<p align="left">&nbsp;<input type="submit" value="Submit" name="B3">
<input type="reset" value="Reset" name="B2"></p>
</form>




<p align="left">&nbsp;</p>
<p align="center">&nbsp;</p>


<% 

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing 
%>

</body>




</html>
Message #2 by =?iso-8859-1?Q?Henri-Fran=E7ois_Depouille?= <hfdepouille@h...> on Mon, 26 Aug 2002 21:45:09 +0200
you cannot change one list box with the result of another with asp becouse
the result of the selection occurs on the client machine (javascript). Then
you'll have to hardcode all the lists in javascripts for your second box.
If you want to do this with asp, call the page with a different querystring
on clicking a selection of the first box and then you have to check the
querystring and making the second box with this.

----- Original Message -----
From: "Ray Kano" <rkano@a...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, August 26, 2002 7:31 PM
Subject: [asp_databases] Populating another drop down list, based on the
selection from another drop down list


> Here is my code below, I query the database to get me a recordset...the
> company name populates my first drop. So based on that selection, I want
> to automatically populate the address and a contact person drop down.
> There may be more that one contact per company, so I want that to be a
> drop down as well. You will see my reference to this drop down as I have
> put in a comment in CAPS where my code starts:
>
> <%@language=VBScript%>
> <%
> Dim objConn, strSQL, objRS, lngCol
> Set objConn = Server.CreateObject("ADODB.Connection")
> ObjConn.ConnectionString = "DSN=RMA;UID=sa;PWD=1"
> objConn.Open
>
> strSQL = "select rmanum from RMA order by RMANum desc "
> Set objRS=objConn.Execute(strSQL)
>
> strSQL1 = "SELECT distinct company, contact, title, phone1, address1" &_
> " FROM contact1 where company > ' ' order by company "
> Set objRS1=objConn.Execute(strSQL1)
>
> %>
>
>
>
>
> <html>
>
> <head>
> <title>New Page 1</title>
> </head>
>
> <body bgcolor="#FFFFFF">
> <a href="/WebApps/RMA/homepage.asp"><p><img border="0"
> src="Stuff/rma_online.gif"></p></a>
>
> <p align="center"><b><font face="Arial Black" color="#0000FF"><i>A Test
> Form Page for RMA's</i></font></b></p>
> <form method=post action="addnewrma.asp" name=newrma>
> <p align="center">&nbsp;</p>
> <p align="left">  &nbsp;  <p>
> <table border="1" width="100%" bordercolor="#FFFFFF" height="183">
>   <tr>
>     <td width="15%" height="19">
>       <b><font color="#800080">Today's Date :&nbsp; </font></b> </td>
>     <td width="51%" height="19"><%=Mydate%></td>
>   </tr>
>   <tr>
>     <td width="15%" height="22">
>       <p align="left"><b><font color="#800080">RMA Number
:</font></b></td>
>     <td width="51%" height="22"><input type="text" size=10 value="<%
> NewMaxRma %>" name="rmanum" id="1" tabindex="1"></td>
>   </tr>
>
>
> <!-- HERE IS WHERE MY FIRST DROP DOWN STARTS -->
>
>   <tr>
>     <td width="15%" height="23">
>       <p align="left"><b><font color="#800080">Company
> Name&nbsp; :</font></b></td>
>     <td width="51%" height="23">
>
>
> <Select Name="Customer" size="1"
>   onchange="alert(options[this.selectedIndex].value)">
>
> <BR>
>
> <%While Not objRS1.EOF%>
>
> <option value="<%= objRS1("company") %>"><%= objRS1("company") %></option>
>
> <%
> objRS1.MoveNext
> Wend
>
> %>
> </Select>
>
>
>
>
>     </td>
>   </tr>
>
>   <tr>
>     <td width="15%" height="23">
>       <p align="left"><b><font color="#800080">Address :</font></b></td>
>     <td width="51%" height="23"><input type="text" size=50 value=""
> name="address1" id="3" tabindex="3"></td>
>   </tr>
>   <tr>
>     <td width="15%" height="23">
>       <p align="left"><b><font color="#800080">Contact
> Person :&nbsp;</font></b></td>
>     <td width="51%" height="23"><input type="text" size=50 value=""
> name="contact" id="4" tabindex="4"></td>
>   </tr>
>   <tr>
>     <td width="15%" height="38"><b><font color="#800080">Telephone
> Number :</font></b></td>
>     <td width="51%" height="38"><input type="text" size=15 value=""
> name="telnumber" id="5" tabindex="5"></td>
>   </tr>
>   <tr>
>     <td width="15%" height="37"><b><font color="#800080">Serial
> Number :</font></b></td>
>     <td width="51%" height="37"><input type="text" size=15 value=""
> name="sernum" id="50" tabindex="6"></td>
>   </tr>
> </table>
> <p align="left"><b><font color="#800080">Product
> Description :</font></b></p>
> <p align="left"><textarea rows="3" name="proddesc" cols="60" id="6"
> tabindex="7"></textarea></p>
> <p align="left"><b><font color="#800080">Problem :</font></b></p>
> <p align="left"><textarea rows="3" name="Problem" cols="60" id="60"
> tabindex="8"></textarea></p>
> <table border="1" width="505" bordercolor="#FFFFFF">
>   <tr>
>     <td width="135"><b><font color="#800080">Date Received :</font> </b>
> </td>
>     <td width="80"> <input type="text" size=10 value="" name="daterec"
> id="7" tabindex="9"></td>
>     <td width="151"><b><font color="#800080">&nbsp;&nbsp;&nbsp;&nbsp; Date
> Returned :</font> </b> </td>
>     <td width="111"> <input type="text" size=10 value="" name="dateret"
> id="8" tabindex="10"></td>
>   </tr>
> </table>
> <p align="left"><b><font color="#800080">&nbsp;Work Performed :</font></b>
> </p>
> <p align="left">&nbsp;<textarea rows="3" name="workperf" cols="60" id="9"
> tabindex="11"></textarea></p>
> <p align="left"><b><font color="#800080">&nbsp;Parts
> Needed :</font></b></p>
> <p align="left">&nbsp;<textarea rows="3" name="partneed" cols="60" id="10"
> tabindex="12"></textarea></p>
> <p align="left">&nbsp;<input type="submit" value="Submit" name="B3">
> <input type="reset" value="Reset" name="B2"></p>
> </form>
>
>
>
>
> <p align="left">&nbsp;</p>
> <p align="center">&nbsp;</p>
>
>
> <%
>
> objRS.Close
> Set objRS = Nothing
> objConn.Close
> Set objConn = Nothing
> %>
>
> </body>
>
>
>
>
> </html>
>
Message #3 by "Kim Iwan Hansen" <kimiwan@k...> on Mon, 26 Aug 2002 21:52:27 +0200
You don't have to hardcode those secondary lists - you just build the lines
of javascript in the asp code the same way as you build html code.

-Kim

> -----Original Message-----
> From: Henri-François Depouille [mailto:hfdepouille@h...]
> Sent: 26. august 2002 21:45
> To: ASP Databases
> Subject: [asp_databases] Re: Populating another drop down list, based on
> the selection from another drop down list
>
>
> you cannot change one list box with the result of another with asp becouse
> the result of the selection occurs on the client machine
> (javascript). Then
> you'll have to hardcode all the lists in javascripts for your second box.


Message #4 by Vijay G <happygv@y...> on Tue, 27 Aug 2002 14:39:49 -0700 (PDT)
I have done a similar one, try this if you are interested.

You can assign the value of the list items such that it contains the asp page name with some querystring values, that identify the
values to be filled in the other list.

something like this.

<option........................value="Test.asp?id=<%=FieldID%>">

and <select> tag's on change event should have something like this.

<select ............... onchange="Refresh()">

and this function should be put under the <script language=javascript> tag, under <Head> part.

function Refresh()
{
             window.location.href=document.FORM_NAME.LIST_NAME.options[document.FORM_NAME.LSIT_NAME.selectedIndex].value;
}

so that once this value is selected from the list, the page refreshes with the Querystring set, that decides the values to be filled
in the second one.

Hope this helps.

Cheers!!!
Vijay G

 Henri-François_Depouille wrote:
you cannot change one list box with the result of another with asp becouse
the result of the selection occurs on the client machine (javascript). Then
you'll have to hardcode all the lists in javascripts for your second box.
If you want to do this with asp, call the page with a different querystring
on clicking a selection of the first box and then you have to check the
querystring and making the second box with this.

----- Original Message -----
From: "Ray Kano" 
To: "ASP Databases" 
Sent: Monday, August 26, 2002 7:31 PM
Subject: [asp_databases] Populating another drop down list, based on the
selection from another drop down list


> Here is my code below, I query the database to get me a recordset...the
> company name populates my first drop. So based on that selection, I want
> to automatically populate the address and a contact person drop down.
> There may be more that one contact per company, so I want that to be a
> drop down as well. You will see my reference to this drop down as I have
> put in a comment in CAPS where my code starts:
>
> 
> > Dim objConn, strSQL, objRS, lngCol
> Set objConn = Server.CreateObject("ADODB.Connection")
> ObjConn.ConnectionString = "DSN=RMA;UID=sa;PWD=1"
> objConn.Open
>
> strSQL = "select rmanum from RMA order by RMANum desc "
> Set objRS=objConn.Execute(strSQL)
>
> strSQL1 = "SELECT distinct company, contact, title, phone1, address1" _
> " FROM contact1 where company > ' ' order by company "
> Set objRS1=objConn.Execute(strSQL1)
>
> %>
>
>
>
>
> 
>
> 
> 
> 
>
> 
> 
> src="Stuff/rma_online.gif">

>
> 
A Test
> Form Page for RMA's

> 
> 
 

> 
 

> 
> 
> 
> Today's Date :  
> 
> 
> 
> 
> 
RMA Number
:

>  [input] > NewMaxRma %>" name=rmanum>
> 
>
>
> 
>
> 
> 
> 
Company
> Name  :

> 
>
>
> > onchange="alert(options[this.selectedIndex].value)">>> >> >> ">>> >
>
>
>
>
> 
> 
>
> 
> 
> 
Address :

>  [input] > name="address1" id="3" tabindex="3">
> 
> 
> 
> 
Contact
> Person : 

>  [input] > name="contact" id="4" tabindex="4">
> 
> 
> Telephone
> Number :
>  [input] > name="telnumber" id="5" tabindex="5">
> 
> 
> Serial
> Number :
>  [input] > name="sernum" id="50" tabindex="6">
> 
> 
> 
Product
> Description :

> 
> tabindex="7">

> 
Problem :

> 
> tabindex="8">

> 
> 
> Date Received : 
> 
>  [input] > id="7" tabindex="9">
>      Date
> Returned : 
>  [input] > id="8" tabindex="10">
> 
> 
> 
 Work Performed :
> 

> 
 > tabindex="11">

> 
 Parts
> Needed :

> 
 > tabindex="12">

> 
  [input] 
>  [input] 

> 
>
>
>
>
> 
 

> 
 

>
>
> >
> objRS.Close
> Set objRS = Nothing
> objConn.Close
> Set objConn = Nothing
> %>
>
> 
>
>
>
>
> 
>



---------------------------------
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes

  Return to Index