473,480 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

two drop down list with javacript and asp

<% Option Explicit %>
<!--#include file="includes/conn.inc"-->
<% Dim rds, ID %>
<% Set rds = Server.CreateObject("ADODB.Recordset") %>
<% rds.Open "select RecID, LocationName from Location ORDER BY
LocationName", connStr, 3, 4 %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Location</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function formHandler(form){
var URL =
document.form.location_name.options[document.form.location_name.selectedIndex].value;
parent.mainframe.location.href = URL;
}
// End -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function formHandler(form1){
var URL =
document.form1.location_network.options[document.form1.location_network.selectedIndex].value;
parent.mainframe.location.href = URL;
}
// End -->
</SCRIPT>
</HEAD>
</head>

<body bgcolor="ccccff">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="19%">&nbsp;</td>
<td width="55%"><font
size="3"><strong>Location</strong></font></td>
<td width="26%"><font size="3"><strong>Network
Subnet</strong></font></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11%">&nbsp;</td>
<td width="48%"><form name="form">
<SELECT NAME="location_name" onChange="javascript:formHandler()"> <div
align="center">
<% Do While NOT rds.EOF %>
<OPTION
value="redirect_loc.asp?ID=<%=rds("RecID")%>"><%=r ds.Fields("LocationName")%></option>
<% rds.movenext %>
<% Loop %>
<%
rds.Close
Set rds = Nothing
%>
</form></td>
<td width="41%"><form name="form1"><div align="center">
<% Dim rsd %>
<% Set rsd = Server.CreateObject("ADODB.Recordset") %>
<% rsd.Open "select RecID, Network from Location ORDER BY
Network", connStr, 3, 4 %>
<SELECT NAME="location_network" onChange="javascript:formHandler()">
<% Do While NOT rsd.EOF %>
<OPTION
value="redirect_network.asp?ID=<%=rsd("RecID")%>"> <%=rsd.Fields("Network")%></option>
<% rsd.movenext %>
<% Loop %>
<%
rsd.Close
Set rsd = Nothing
%>
</form></td>
</tr>
</table>
</body>
</html>

Nov 22 '05 #1
2 2484
"weiwei" <we*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

Do you have a question or problem?
You didn't ask but:

1) Change

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
....
// End -->
</SCRIPT>

to

<script type="text/javascript">
....
</script>

and you only need one.

2) Remove the extar </HEAD> tag.

3) </select> tags are missing.

4) "onChange=" doesn't need "javascript:"

5) The two tables have different coumn (<td>) widths.

6) name="form" is not recommended;
try naming your forms "form1" and "form2".

7) It might be easier to put the ASP logic at the beginning
to build variables then reference them in the HTML.
Here's an untested rework of your code. Watch for word-wrap.

<% Option Explicit %>
<!--#include file="includes/conn.inc"-->
<% Dim op1, op2, rs1, rs2
'*
Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.Open "SELECT RecID, LocationName FROM Location ORDER BY
LocationName", connStr, 3, 4
Do While NOT rs1.EOF
op1 = op1 & " <option value="redirect_loc.asp?ID="
op1 = op1 & rs1("RecID") & ">" & rs1.Fields("LocationName")
op1 = op1 & "</option>" & vbCrLf
rs1.MoveNext
Loop
rs1.Close
Set rs1 = Nothing
'*
Set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.Open "SELECT RecID, Network FROM Location ORDER BY Network",
connStr, 3, 4
Do While NOT rs2.EOF
op2 = op2 & " <option value="redirect_network.asp?ID="
op2 = op2 & rs2("RecID") & ">" & rs2.Fields("Network")
op2 = op2 & "</option>" & vbCrLf
rs2.MoveNext
Loop
rs2.Close
Set rs2 = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Location</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function formHandler(that) {
parent.mainframe.location.href = that.options[that.selectedIndex].value;
}
</script>
</head>
<body bgcolor="#ccccff">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="10%">&nbsp;</td>
<td width="45%"><font size="3"><strong>Location</strong></font></td>
<td width="45%"><font size="3"><strong>Network
Subnet</strong></font></td>
</tr>
</table>
<br>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="10%">&nbsp;</td>
<td align="center" width="45%">
<form name="form1">
<select name="location_name" onChange="formHandler(this)">
<%=op1%>
</select>
</form>
</td>
<td align="center" width="45%">
<form name="form2">
<select name="location_network" onChange="formHandler(this)">
<%=op2%>
</select>
</form>
</td>
</tr>
</table>
</body>
</html>
Nov 22 '05 #2
Cheap Tricks 2: A Dynamically-Linked Listbox
http://www.atgconsulting.com/doublelist.asp
Initially sends all data to the page and then lets JavaScript populate
the second list box.

And similar but better one (improved code and 3 select boxes):
Cheap Tricks 4: A Triple-Linked Listbox
http://www.atgconsulting.com/triplelist.asp

Universal Related Popup Menus v 2.02
http://webreference.com/dev/menus/
Initially sends all data to the page and then lets JavaScript populate
the second list box.

Best regards,
J. Paul Schmidt, Freelance Web and Database Developer
http://www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14202
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
3
6135
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
13
5205
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
2
12594
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
1
2484
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
8
7557
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
5
18701
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
4
9270
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
7324
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
7051
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.