Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   two drop down list with javacript and asp (http://www.velocityreviews.com/forums/t800019-two-drop-down-list-with-javacript-and-asp.html)

weiwei 11-14-2005 10:40 PM

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>


McKirahan 11-14-2005 11:51 PM

Re: two drop down list with javacript and asp
 
"weiwei" <weihuangzhu@gmail.com> wrote in message
news:1132008012.864545.127510@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>



paul@bullschmidt.com 11-15-2005 06:20 AM

Re: two drop down list with javacript and asp
 
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



All times are GMT. The time now is 02:08 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.