Dynamic Drop down list trouble

V

visualbasicide

I have two lists, one above the other, and they are BOTH populated
using vbscript and sql queries.

what I want to happen is when they select something in the top list
(departments) it refreshes the selections available in the bottom list
(individuals)

so in this case, if they select "IT"
then the bottom list will update itself to show only:
"me"
"follower1"
"follower2"

etc.

or if they select "Famous"
the bottom list will update itself to:
"Elvis"
"Dweezle"
"Parry Hotter"

I dont know how to programmatically check which option was selected.
if I can check that out, then I will be able to pull just the names out
of the database that I want.

or maybe set some value in the database for everyone in that
department.
but still that would depend on detecting what is currently selected.

can someone help me out?

heres a bit of the code:


VB:
--------------------------------------------------------------------------------
Sub GetDropDownValues1(dropdownname,tablename,columnname)
'Get the values for the ticketnumber from the database
Set objConn=Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = connectionStr
objConn.Open

'Added: Replace function to avoid basic sql injection
strSQL = "SELECT * FROM " & Replace(tablename, "'", "''") & "'" & "
WHERE " & columnname & " = '" & dropdownvalue & "'"
Set objRS = objConn.Execute(strSQL)
Response.Write "<select name=" & dropdownname & ">"
Do While Not objRS.EOF
If objRS("technicianname") <> "myboss" Then
Response.Write "<option value=" & objRS("" & columnname & "id"
& "") & ">" & objRS("" & columnname & "name" & "") & "</option>"
End If
objRS.MoveNext
Loop
Response.Write "</select>"
objRS.Close
objConn.Close 'Added: Close before freeing resources
Set objRS = Nothing
Set objConn = Nothing
End Sub


ok, maybe to make this a little easier, I need a way to write in an
onclick event to call a function where I can check to see what the
selected value of that option is.

my thinking is that if I can check what <option selected> is, so I can
say, ok, this is IT, so on the next dropdown (before its actually
created) I can filter out anyone that isnt in that department.

my 2nd problem is how to actually update the page, again, my guess is
to just refresh the page when they select a department, and have it
check the selected value, and then display the names in the 2nd box
accordingly.

I heard also something about a session variable? I think this is what I
use to determine what department is currently logged on. but if there
is something similar I can use, to keep a variable in when i refresh
the page, that would be perfect.

if im not correct on this line of reasoning, please do help as I only
understand about half of what im doing and I make the rest up as I go
along, so while it works, its a painfully slow process.
 
M

Mike Brind

I have two lists, one above the other, and they are BOTH populated
using vbscript and sql queries.

what I want to happen is when they select something in the top list
(departments) it refreshes the selections available in the bottom list
(individuals)

so in this case, if they select "IT"
then the bottom list will update itself to show only:
"me"
"follower1"
"follower2"

etc.

or if they select "Famous"
the bottom list will update itself to:
"Elvis"
"Dweezle"
"Parry Hotter"

I dont know how to programmatically check which option was selected.
if I can check that out, then I will be able to pull just the names out
of the database that I want.

or maybe set some value in the database for everyone in that
department.
but still that would depend on detecting what is currently selected.

can someone help me out?

heres a bit of the code:


VB:
--------------------------------------------------------------------------------
Sub GetDropDownValues1(dropdownname,tablename,columnname)
'Get the values for the ticketnumber from the database
Set objConn=Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")

objConn.ConnectionString = connectionStr
objConn.Open

'Added: Replace function to avoid basic sql injection
strSQL = "SELECT * FROM " & Replace(tablename, "'", "''") & "'" & "
WHERE " & columnname & " = '" & dropdownvalue & "'"
Set objRS = objConn.Execute(strSQL)
Response.Write "<select name=" & dropdownname & ">"
Do While Not objRS.EOF
If objRS("technicianname") <> "myboss" Then
Response.Write "<option value=" & objRS("" & columnname & "id"
& "") & ">" & objRS("" & columnname & "name" & "") & "</option>"
End If
objRS.MoveNext
Loop
Response.Write "</select>"
objRS.Close
objConn.Close 'Added: Close before freeing resources
Set objRS = Nothing
Set objConn = Nothing
End Sub


ok, maybe to make this a little easier, I need a way to write in an
onclick event to call a function where I can check to see what the
selected value of that option is.

my thinking is that if I can check what <option selected> is, so I can
say, ok, this is IT, so on the next dropdown (before its actually
created) I can filter out anyone that isnt in that department.

my 2nd problem is how to actually update the page, again, my guess is
to just refresh the page when they select a department, and have it
check the selected value, and then display the names in the 2nd box
accordingly.

I heard also something about a session variable? I think this is what I
use to determine what department is currently logged on. but if there
is something similar I can use, to keep a variable in when i refresh
the page, that would be perfect.

if im not correct on this line of reasoning, please do help as I only
understand about half of what im doing and I make the rest up as I go
along, so while it works, its a painfully slow process.

Have a look at this: http://www.w3schools.com/ajax/ajax_database.asp and see
if you can apply the principal detailed there. If you get stuck, get back
to us.
 

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

Similar Threads


Staff online

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top