Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > two drop down list with javacript and asp

Reply
Thread Tools

two drop down list with javacript and asp

 
 
weiwei
Guest
Posts: n/a
 
      11-14-2005
<% 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>

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      11-14-2005
"weiwei" <> wrote in message
news: 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>


 
Reply With Quote
 
 
 
 
paul@bullschmidt.com
Guest
Posts: n/a
 
      11-15-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
Auto Drop down a Drop Down List xxbmichae1@supergambler.com Javascript 5 11-23-2005 01:35 AM
two drop down list with javacript weiwei Javascript 4 11-14-2005 11:37 PM
New to .NET, can I have one drop down box control the data of another drop down box using a database? SirPoonga ASP .Net 2 01-07-2005 10:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57