Conditional List Box in ASP

G

Guy Hocking

Hi there,

I am having a few problems compiling a list box that is conditional on what
is selected in another list box.
What i need is a List box (lstArea) that displays one thing when the List
Box (lstRegion) is selected East or West. Basically the areas will change
when East or West is selected in lstRegion.

The data comes from an SQL Server view, and my current non-working code is
as follows, my syntax in the SQL statement is completly wrong, i have no
idea how to go about this..
The View has 2 columns, vchrLong_Desc and vchrArea_Name, i want the new list
box (lstArea) to display vchrArea_Name when the List Box lstRegion displays
vchrLong_Desc.

************************
<select name="lstArea" size="1"><br>
<option value="">Please Select </option>
<%
Dim SQL, RS,

SQL = "SELECT * from vw_SOLS_RegionsAreas_u WHERE
vw_SOLS_RegionsAreas_u.vchrLong_Desc =" ("lstRegion")""

set RS = DataConnection.Execute(SQL)
If not RS.EOF then
while not RS.EOF
Response.write("<option
value='"&RS("vchrArea_Name")&"'>"&RS("vchrArea_Name")&"</option>")
RS.movenext()
wend
else
Response.write("")
end if
%>
</select>
***************************

Hope that is not too confusing,
I am new to ASP so you will have to forgive me for being nieve

Thanks in advance

Guy
 
B

Bob Barrows

Guy said:
Hi there,

I am having a few problems compiling a list box that is conditional
on what is selected in another list box.
What i need is a List box (lstArea) that displays one thing when the
List Box (lstRegion) is selected East or West. Basically the areas
will change when East or West is selected in lstRegion.

The data comes from an SQL Server view, and my current non-working
code is as follows, my syntax in the SQL statement is completly
wrong, i have no idea how to go about this..
The View has 2 columns, vchrLong_Desc and vchrArea_Name, i want the
new list box (lstArea) to display vchrArea_Name when the List Box
lstRegion displays vchrLong_Desc.

http://www.aspfaq.com/show.asp?id=2270

Bob Barrows

PS. I realize you are new, so you probably are not aware that you've
committed a breach of netiquette here by posting an off-topic question.

Just so you know, ASP is server-side technology, ie, it operates on the web
server. By the time the client sees anything in the browser, ASP is usually
finished. All subsequent operations (such as responding to users' actions:
clicking with the mouse or selecting an option in a listbox) are no longer
ASP operations, making them off-topic for this newsgroup. The appropriate
newsgroups for this type of question (client-side code) are those that
contain "dhtml" (dynamic html) in their names, or
microsoft.public.scripting.jscript, or microsoft.public.scripting.vbscript.
With a few exceptions, questions about activity that occurs on the server
(server-side code) before the client sees the response in the browser, are
the only on-topic questions for these asp newsgroups. (I notice you included
the .iis newsgroup, which was totally inappropriate, since that newsgroup
deals with the web server itself). It helps to browse a little in the
newsgroups before posting to see which types of questions are deemed
appropriate - you may even discover the answer to your question without
posting. Use Google to seach for answers before posting: you will save
yourself (and us) some time.

I do congratulate you for cross-posting instead of multi-posting, however.
Nothing burns us up more than responding to a question in one newsgroup only
to find it's been answered in another group.
 
G

Guy Hocking

Hi,

I appreciate your points made in your reply, however, the code i am talking
about may well be client side but it will post it to an ASP page to sort out
and display the detail.
Explain this to me, how will i get the data from the SQL server onto the
page in the first place? will it not need to be an ASP page in order to do
this - then sort out the client options once its there?
If this is incorrect forgive me, as i stated i am new to ASP and its
sisters.

Please forgive me, as i feel your response was kind of patronising, i
appreciate what you guys do as i frequently answer questions in the Exchange
newsgroups, but your post was simply a point being made rather than helping
me with my query.
Whether client or server side the operation still contains ASP at some
stage, making this post not so as in-appapropriate as you make out.

I will post to the apropriate newsgroups, my apologies to any other MVP with
their knickers in a twist,

Kind Regards

Guy Hocking
MCSE
 
H

Harag

if you reread Bobs post the very first line was helping you...

Look at all the links and that will tell you how to do it.

Basically you need CLIENT side code to change the drop down boxes with
information... once you get that look at it and learn how its doing
it.. once you got that then you can tell the client side code the date
from the ASP db you need.


If you find that client side javascript code is to advanced for you
then you will have to do it server side, but this is not as
"professional" as it calls back to the server each time.


check out matts site for more info.

http://www.mattkruse.com/javascript/



Al.
 
D

Dan Boylett

Guy Hocking said:
Hi there,

I am having a few problems compiling a list box that is conditional on what
is selected in another list box.
What i need is a List box (lstArea) that displays one thing when the List
Box (lstRegion) is selected East or West. Basically the areas will change
when East or West is selected in lstRegion.

The data comes from an SQL Server view, and my current non-working code is
as follows, my syntax in the SQL statement is completly wrong, i have no
idea how to go about this..
The View has 2 columns, vchrLong_Desc and vchrArea_Name, i want the new list
box (lstArea) to display vchrArea_Name when the List Box lstRegion displays
vchrLong_Desc.

************************
<select name="lstArea" size="1"><br>
<option value="">Please Select </option>
<%
Dim SQL, RS,

SQL = "SELECT * from vw_SOLS_RegionsAreas_u WHERE
vw_SOLS_RegionsAreas_u.vchrLong_Desc =" ("lstRegion")""

This last bit could be a problem.... for lots of reasons.

Are you having your page submit when the first box is selected? Are all your
select boxes in a Form?

You would need to have something like this :

<%
If Request.Form() <> "" Then ' Form submitted'
DropDown1 = Trim(Request.Form("DropDown1"))

If DropDown1 <> "" Then
sSQL = "SELECT * FROM vw_SOLS_RegionsAreas_u WHERE sw_etc = '" &
DropDown1 & "'"
Set RS = DataConn.Execute(SQL)
If NOt (RS.eof and RS.BOF) Then
Response.write "<Select name = ""DropDown2"">"
Do While Not Rs.Eof
Response.write "<option value = """ & RS("WhichEverIDField") &
""">" & RS("WhichEverTextField
Rs.Movenext
Loop
Response.write "</select>"
Else
Response.write "No records found!"
End If
RS.CLose
Set RS = Nothing
End If


%>
 
J

Jeff Cochran

I appreciate your points made in your reply, however, the code i am talking
about may well be client side but it will post it to an ASP page to sort out
and display the detail.

The client side code isn't on topic in the asp.db group. The ASP part
is barely on topic for the other groups you posted to. To get the
best answer to your quesion, use the correct groups. And when someone
suggests a different group, follow that advice.
Explain this to me, how will i get the data from the SQL server onto the
page in the first place? will it not need to be an ASP page in order to do
this - then sort out the client options once its there?

Well, umm... Not completely. But that's not an issue. You asked
about the client-side functions, not getting the results from the
database on the server side.

You're new to ASP, and need to understand that an ASP "page" may have
server-side and client-side code, as well as HTML coding, DHTML and
quite possibly a Perl script tacked in for good measure. Just because
you use ASP and the problem appears on the page doesn't mean it's an
ASP issue. Heck, it could be a router, DNS, IIS, authentication, NTFS
permissions or Internet Explorer issue. Each technology has some very
talented people voluntarily helping, but none of us know it all. So
we point you to the best place to resolve your issue.

We don't hate you for it, even though we may sound snotty (answering
the same request a dozen times in a day makes us that way), our real
goal is actually getting you working correctly. If we can also give
you the knowledge to figure it out yourself the next time, even
better.

Jeff
 
G

Guy Hocking

Cheers Guys and Gals for your help,

Once again my apologies to those i may of offended.
Keep up the good work ppl

Thanks again
 
B

Brynn

I would suggest using ASP to write out the first select ... then you
will have to use asp to write out the next select for the change in
the first

I would suggest as you explore your javascript needs for this problem,
you make it easy on yourself and look into splitting strings in js

<script language="javascript"
var secondCommaString

switch(valueOfFirstSelectBox)

<%
loop through 1st box variables to get ...

With Response
.Write "case 'firstBoxValue1':" & vbNewLine

.Write "secondCommaString = string of variables for javascript to
use to create an array and create new select bow" & vbNewLine

..Write "break" & vbNewLine
End With
%>

//then later in js split the commaString into a JS array and write
"show" the span and write the 2nd select box with the array of values




Anyway, this is a semi-complex piece of code ... and a little lengthy
for me to put here ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top