|
 |
asp_web_howto thread: select object
Message #1 by "Nisha" <nishanam@y...> on Thu, 7 Dec 2000 18:43:07 -0000
|
|
Hi
I have 2 drop down boxes Division & Community.
I want to load the community drop down based on what the user selects in
the division drop-dowm.
Both are in the same page.
I have used ASP to load the combo box and then in the Division drop dowm
boxes's onchange event I have a Javascript which gets the user selction.
But how to take that value from the javascript and write an ASP script to
load the community drop down from the access database with only those
communities under that division.
Here is the code.
<%
Dim Conn
Dim rsDivision
Dim rsCommunity
set Conn = Server.CreateObject("ADODB.Connection")
set rsDivision = server.createobject("ADODB.Recordset")
set rsCommunity = server.createobject("ADODB.Recordset")
Conn.open "DSN=EngleInfo"
rsDivision.open "Divisions",conn
rsCommunity.open "EngleProjects",conn
%>
<form action="showLots.asp" method=Post name="frmProduction" onSubmit="return VerifyData()">
<table width=60%>
<tr>
<td><b>Select Division</b> <font color="red">*</font></td>
<td><SELECT id=cboDivision name=cboDivision
OnChange="LoadDivision()"><OPTION VALUE = ""></OPTION>
<%
while not rsDivision.EOF
%>
<OPTION Value = "<% = rsDivision.fields("CompanyName") %>">
<% = rsDivision.fields("CompanyName") %></OPTION>
<%
rsDivision.MoveNext
wend
%>
</select></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><b>Select Community</b> <font color="red">*</font></td>
<td>
<SELECT id=cboCommunity name=cboCommunity
><OPTION VALUE = ""></OPTION>
<%
while not rsCommunity.EOF
%>
<OPTION Value = "<% = rsCommunity.fields("ProjectName") %>">
<% = rsCommunity.fields("ProjectName") %></OPTION>
<%
rsCommunity.MoveNext
wend
%>
</select>
</td>
</tr>
</table><p></p><br>
THE JAVASCRIPT
function LoadDivision()
{
Division=(document.elements.cboDivision.options[document.frmProduction.elements.cboDivision.selectedIndex].value)
}
I would appreciate the help.
Thanks
Nisha
Message #2 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Fri, 8 Dec 2000 10:36:35 -0000
|
|
Unless the amout of options is too big, in the ASP write a seperate select
for each group of communities. Then use CSS to hide all apart from the
first. Then write some javascript that will simply hide the select that is
being displayed, and display the appropriate one. The page make take longer
to load doing it this way, but then it works very quickly once loaded in the
client.
-----Original Message-----
From: Nisha [mailto:nishanam@y...]
Sent: Friday, December 08, 2000 6:14 AM
To: ASP Web HowTo
Subject: [asp_web_howto] select object
Hi
I have 2 drop down boxes Division & Community.
I want to load the community drop down based on what the user selects in
the division drop-dowm.
Both are in the same page.
I have used ASP to load the combo box and then in the Division drop dowm
boxes's onchange event I have a Javascript which gets the user selction.
But how to take that value from the javascript and write an ASP script to
load the community drop down from the access database with only those
communities under that division.
Here is the code.
<%
Dim Conn
Dim rsDivision
Dim rsCommunity
set Conn = Server.CreateObject("ADODB.Connection")
set rsDivision = server.createobject("ADODB.Recordset")
set rsCommunity = server.createobject("ADODB.Recordset")
Conn.open "DSN=EngleInfo"
rsDivision.open "Divisions",conn
rsCommunity.open "EngleProjects",conn
%>
<form action="showLots.asp" method=Post name="frmProduction"
onSubmit="return VerifyData()">
<table width=60%>
<tr>
<td><b>Select Division</b> <font color="red">*</font></td>
<td><SELECT id=cboDivision name=cboDivision
OnChange="LoadDivision()"><OPTION VALUE
""></OPTION>
<%
while not rsDivision.EOF
%>
<OPTION Value = "<% = rsDivision.fields("CompanyName") %>">
<% = rsDivision.fields("CompanyName") %></OPTION>
<%
rsDivision.MoveNext
wend
%>
</select></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><b>Select Community</b> <font color="red">*</font></td>
<td>
<SELECT id=cboCommunity name=cboCommunity
><OPTION VALUE = ""></OPTION>
<%
while not rsCommunity.EOF
%>
<OPTION Value = "<% = rsCommunity.fields("ProjectName") %>">
<% = rsCommunity.fields("ProjectName") %></OPTION>
<%
rsCommunity.MoveNext
wend
%>
</select>
</td>
</tr>
</table><p></p><br>
THE JAVASCRIPT
function LoadDivision()
{
Division=(document.elements.cboDivision.options[document.frmProduction.eleme
nts.cboDivision.selectedIndex].value)
}
I would appreciate the help.
Thanks
Nisha
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
Message #3 by Imar Spaanjaars <Imar@S...> on Fri, 08 Dec 2000 11:46:29 +0100
|
|
There is a good article on asptoday.com dealing with just this subject.
You can find it at:
http://www.asptoday.com/articles/20000414.htm
HtH
Imar
At 10:14 PM 12/7/2000 -0800, you wrote:
>Hi
>
>I have 2 drop down boxes Division & Community.
>I want to load the community drop down based on what the user selects in
>the division drop-dowm.
>Both are in the same page.
>I have used ASP to load the combo box and then in the Division drop dowm
>boxes's onchange event I have a Javascript which gets the user selction.
>But how to take that value from the javascript and write an ASP script to
>load the community drop down from the access database with only those
>communities under that division.
>Here is the code.
><%
>Dim Conn
>Dim rsDivision
>Dim rsCommunity
>
>
>set Conn = Server.CreateObject("ADODB.Connection")
>set rsDivision = server.createobject("ADODB.Recordset")
>set rsCommunity = server.createobject("ADODB.Recordset")
>
>
>Conn.open "DSN=EngleInfo"
>rsDivision.open "Divisions",conn
>rsCommunity.open "EngleProjects",conn
>
>%>
>
><form action="showLots.asp" method=Post name="frmProduction"
>onSubmit="return VerifyData()">
><table width=60%>
><tr>
><td><b>Select Division</b> <font color="red">*</font></td>
><td><SELECT id=cboDivision name=cboDivision
> OnChange="LoadDivision()"><OPTION VALUE =
> ""></OPTION>
><%
>while not rsDivision.EOF
>%>
><OPTION Value = "<% = rsDivision.fields("CompanyName") %>">
><% = rsDivision.fields("CompanyName") %></OPTION>
><%
>rsDivision.MoveNext
>wend
>%>
></select></td>
></tr>
><tr></tr>
><tr></tr>
><tr>
><td><b>Select Community</b> <font color="red">*</font></td>
><td>
><SELECT id=cboCommunity name=cboCommunity
> ><OPTION VALUE = ""></OPTION>
><%
>while not rsCommunity.EOF
>%>
><OPTION Value = "<% = rsCommunity.fields("ProjectName") %>">
><% = rsCommunity.fields("ProjectName") %></OPTION>
><%
>rsCommunity.MoveNext
>wend
>%>
></select>
></td>
></tr>
></table><p></p><br>
>
>THE JAVASCRIPT
>function LoadDivision()
>{
>Division=(document.elements.cboDivision.options[document.frmProduction.elements.cboDivision.selectedIndex].value)
>
>}
>
>I would appreciate the help.
>Thanks
>Nisha
>
Message #4 by "Harsh Nandu" <harsh_stgil@h...> on Fri, 08 Dec 2000 11:03:29 -0000
|
|
Hi,
Check the alterations.
I hope it helps.
Regds,
Harsh
>From: "Nisha" <nishanam@y...>
>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>
>To: "ASP Web HowTo" <asp_web_howto@p...>
>Subject: [asp_web_howto] select object
>Date: Thu, 07 Dec 2000 22:14:28 -0800
>
>Hi
>
>I have 2 drop down boxes Division & Community.
>I want to load the community drop down based on what the user selects in
>the division drop-dowm.
>Both are in the same page.
>I have used ASP to load the combo box and then in the Division drop dowm
>boxes's onchange event I have a Javascript which gets the user selction.
>But how to take that value from the javascript and write an ASP script to
>load the community drop down from the access database with only those
>communities under that division.
>Here is the code.
><%
>Dim Conn
>Dim rsDivision
>Dim rsCommunity
>
>
>set Conn = Server.CreateObject("ADODB.Connection")
>set rsDivision = server.createobject("ADODB.Recordset")
>set rsCommunity = server.createobject("ADODB.Recordset")
>
>
>Conn.open "DSN=EngleInfo"
>rsDivision.open "Divisions",conn
if trim(Request.QueryString("div"))<>"" then
rsCommunity.open "select * from EngleProjects where div='" &
trim(Request.QueryString("div")) & "'" ,conn
else
>rsCommunity.open "EngleProjects",conn
>
>%>
>
<script language="javascript">
<!--
function LoadDivision()
{
var
val=document.frm.cboDivision.option[document.frm.cboDivision.selectedIndex].value;
location.url="current_page.asp?div="+val;
}
//-->
</script>
<form action="showLots.asp" method=Post name="frmProduction"
onSubmit="return VerifyData()" name="frm" >
><table width=60%>
><tr>
><td><b>Select Division</b> <font color="red">*</font></td>
><td><SELECT id=cboDivision name=cboDivision
> OnChange="LoadDivision()"><OPTION VALUE = ""></OPTION>
><%
>while not rsDivision.EOF
>%>
><OPTION Value = "<% = rsDivision.fields("CompanyName") %>">
><% = rsDivision.fields("CompanyName") %></OPTION>
><%
>rsDivision.MoveNext
>wend
>%>
></select></td>
></tr>
><tr></tr>
><tr></tr>
><tr>
><td><b>Select Community</b> <font color="red">*</font></td>
><td>
><SELECT id=cboCommunity name=cboCommunity
> ><OPTION VALUE = ""></OPTION>
><%
>while not rsCommunity.EOF
>%>
><OPTION Value = "<% = rsCommunity.fields("ProjectName") %>">
><% = rsCommunity.fields("ProjectName") %></OPTION>
><%
>rsCommunity.MoveNext
>wend
>%>
></select>
></td>
></tr>
></table><p></p><br>
>
>THE JAVASCRIPT
>function LoadDivision()
>{
>Division=(document.elements.cboDivision.options[document.frmProduction.elements.cboDivision.selectedIndex].value)
>
>}
>
>I would appreciate the help.
>Thanks
>Nisha
>
Message #5 by "Jeremy Wood" <jewood@c...> on Fri, 8 Dec 2000 07:48:58 -0500
|
|
This is exactly a feature we have been including in quite a few of our
projects. I have two ways that you can do this, with a high recommendation
as to the one you should use.
First, you could preload all of the possible combinations into a few
javascript arrays. Then, based on the item selected in the first dropdown
you could reload the second. Positives: quite fast, no return trip to the
server to download the whole page, initial download takes longer (get
recordset and download)
The second option is to use Remote Scripting
(http://msdn.microsoft.com/workshop/languages/clinic/scripting041299.asp
and
http://msdn.microsoft.com/scripting/default.htm?/scripting/RemoteScripting/default.htm).
This will allow you to only preload the first dropdown as you do now, but
then make a query to the server based on the onChange event and write the
results to the second dropdown, without reloading the page! I am really
impressed with this method and highly recommend it.
Anybody else?
~~~~~~~~~~~~~~~~~~~~~~
Jeremy A. Wood
Web Developer, Lead
Enterprise Engineering Division
"Nisha"
<nishanam@y... To: "ASP Web HowTo" <asp_web_howto@p...>
oo.com> cc:
Subject: [asp_web_howto] select object
12/08/2000
01:14 AM
Please
respond to
"ASP Web
HowTo"
Hi
I have 2 drop down boxes Division & Community.
I want to load the community drop down based on what the user selects in
the division drop-dowm.
Both are in the same page.
I have used ASP to load the combo box and then in the Division drop dowm
boxes's onchange event I have a Javascript which gets the user selction.
But how to take that value from the javascript and write an ASP script to
load the community drop down from the access database with only those
communities under that division.
Here is the code.
<%
Dim Conn
Dim rsDivision
Dim rsCommunity
set Conn = Server.CreateObject("ADODB.Connection")
set rsDivision = server.createobject("ADODB.Recordset")
set rsCommunity = server.createobject("ADODB.Recordset")
Conn.open "DSN=EngleInfo"
rsDivision.open "Divisions",conn
rsCommunity.open "EngleProjects",conn
%>
<form action="showLots.asp" method=Post name="frmProduction" onSubmit
="return VerifyData()">
<table width=60%>
<tr>
<td><b>Select Division</b> <font color="red">*</font></td>
<td><SELECT id=cboDivision name=cboDivision
OnChange="LoadDivision()"><OPTION
VALUE = ""></OPTION>
<%
while not rsDivision.EOF
%>
<OPTION Value = "<% = rsDivision.fields("CompanyName") %>">
<% = rsDivision.fields("CompanyName") %></OPTION>
<%
rsDivision.MoveNext
wend
%>
</select></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><b>Select Community</b> <font color="red">*</font></td>
<td>
<SELECT id=cboCommunity name=cboCommunity
><OPTION VALUE = ""></OPTION>
<%
while not rsCommunity.EOF
%>
<OPTION Value = "<% = rsCommunity.fields("ProjectName") %>">
<% = rsCommunity.fields("ProjectName") %></OPTION>
<%
rsCommunity.MoveNext
wend
%>
</select>
</td>
</tr>
</table><p></p><br>
THE JAVASCRIPT
function LoadDivision()
{
Division
=(document.elements.cboDivision.options[document.frmProduction.elements.cboDivision.selectedIndex].value)
}
I would appreciate the help.
Thanks
Nisha
|
|
 |