Click to See Complete Forum and Search --> : ASP and Dynamically Updating Combo Box


jester
01-11-2001, 11:42 AM
Here's the situation. I need to create two combo boxes, using ASP and VBScript to fill the information from a database. The second combo box's information depends on what has been selected in the first combo box. When the user selects something in the first combo box, the OnClick property triggers the UpdateSecondCB() function using VBScript. Now my problem lies in accessing the database. I've tried the regular way of(located below) accessing the database, but this doesn't work. Is there a special way to access a database in a function?

btw, I'm getting the error "Object Required: 'Server'" at the </body> statement. This function is located inside of the <body> field.

<script language="VBScript">

sub UpdateSecondCB

WhatIWant = clng(FORM.OPTION.value)

set conn = server.createobject("ADODB.Connection")
conn.open "MyDatabase","",""
set recordset = server.createobject("ADODB.Recordset")

strSQL = "SELECT FieldName, FieldID FROM Table WHERE Field1ID = " & WhatIWant & ";"
recordset.open strSQL, conn, 3, 3

While Not recordset.EOF
set objOption = document.createElement("OPTION")
objOption.Value = recordset.Fields("FieldID")
objOption.Text = recordset.Fields("FieldName")
Search.Topics.add objOption
recordset.MoveNext
WEnd
recordset.Close
conn.Close
set conn = Nothing
set recordset = Nothing

end sub
</script>

I've searched many web sites trying to find some information, this is my last resort.

------------------
- jesteŽ

How could tomorrow ever follow today?

jester
01-12-2001, 04:42 AM
No need to boggle your mind anymore. I've figured it out myself. For those of you interested, I can give you the source if you like. Right now the code is in its beta stage and should be completely done by the end of the weekend. Just gotta fix a bug or two and add dynamic arrays in the picture. What can I say, I'm a stickler for memory. Also makes the program more robust to the database.

I'll give you guys the gist of it. Using VBScript and ASP, I dynamically created JavaScript arrays and the populateComboBox() function. The arrays are holding the information from the database. When the proper item is selected from the combobox, the populateComboBox() function displays the array associated with the item. This is probably the hard way to do it, but it works for now. If anyone else has a suggestion, i'll be glad to hear it. Now I can honestly say that I've used three languages at the same time, if you consider ASP a language. http://www.sharkyforums.com/ubb/tongue.gif

------------------
- jesteŽ

How could tomorrow ever follow today?

GrayCalx
01-12-2001, 05:39 PM
Yeah I think he jsut hit on it. Using a client-side script (Javascript or VBscript) you can't access a database unless you're using RDS (fairly complicated and totally destroys any protection for the db).

So what you're going to do, is select out all the possible options using ASP or whatever server side script you have. Then when the combobox's onchange event fires pass a string or arr (of possible options) to the script and parse it for the ones that match the current value of the combobox. Its really not that hard, parsing is prolly the worst and it'll only take a few lines.

Mail me if you need more help.

jester
01-12-2001, 05:54 PM
Originally posted by GrayCalx:
Yeah I think he jsut hit on it. Using a client-side script (Javascript or VBscript) you can't access a database unless you're using RDS (fairly complicated and totally destroys any protection for the db).

So what you're going to do, is select out all the possible options using ASP or whatever server side script you have. Then when the combobox's onchange event fires pass a string or arr (of possible options) to the script and parse it for the ones that match the current value of the combobox. Its really not that hard, parsing is prolly the worst and it'll only take a few lines.

Mail me if you need more help.


I thought about the client having to access my database through a script after I wrote the first post. What your talking about is exactly what I did.

------------------
- jesteŽ

How could tomorrow ever follow today?