Home

News

Forums

Hardware

CPUs

Motherboards

Video

Guides

CPU Prices

RAM Prices


Sharky Extreme : Forums:


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post ASP and Dynamically Updating Combo Box

    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?
    - jesteŽ

    How could tomorrow ever follow today?

  2. #2
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post

    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.

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

    How could tomorrow ever follow today?
    - jesteŽ

    How could tomorrow ever follow today?

  3. #3
    Tiger Shark GrayCalx's Avatar
    Join Date
    Nov 2000
    Location
    Northern VA
    Posts
    569

    Post

    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.
    XP 1600+
    MSI KT333
    512 PC2700
    AOpen Geforce4 4200

  4. #4
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post

    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?
    - jesteŽ

    How could tomorrow ever follow today?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts