SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic Populate Combos - Withouth refresh

    Hi

    At the first my english is not good. Hope i can explain that what is my problem. And hope you can understand my problem too.


    I need a script like that. I ll explain it like coded like VB



    *****************************
    *Script
    *****************************
    private sub PopCombo(PopComboName,SQLTable)
    sql="select field1 from " & SQLTable
    set rs=conn.execute(SQL)

    PopComboName.clear

    do until rs.eof
    PopComboName.additem RS("field1")
    rs.movenext
    loop
    end sub




    *****************************
    *Page
    *****************************

    ...
    ...
    <select id="f_country" onchange="PopCombo(f_city,"cities")">

    ...
    ...

    <select id="f_city" onchange="PopCombo(f_area,"area")">

    ...
    ...

    <select id="f_area">

    ..
    Is it possible to do this in Java ? It is so important for me. Thanks alot for your help from now.

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if VBScript variable names are case-sensitive, but if they are, you're passing a different variable than the one declared here:

    sql="select field1 from " & SQLTable
    set rs=conn.execute(SQL)

    Also, your code appears to be mixing server-side and client-side script. To dynamically fetch the options for the second SELECT element without reloading the page, you need to use AJAX on the client side to request a server script that executes the SQL query.

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    WWW - he posted the VB code as an example of what he's trying to achieve; not to have that code debugged. (BTW - VBScript is NOT case sensitive).

    Fatih - where will the data for the comboboxes come from? Assuming it's coming from a database, and assuming you're trying to do this without reloading the page each time, there are two basic ways to achieve this ...

    1. Get all possible data options from the database and store in Javascript arrays.

    2. Get the first set of data (for the 1st combobox), then when a selection is made use AJAX (XMLHttpRequest) to get the data for the 2nd combobox and populate it, then repeat as needed for subsequent lists.

    I suggest you search for dynamic dropdown lists.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    WWW - he posted the VB code as an example of what he's trying to achieve; not to have that code debugged. (BTW - VBScript is NOT case sensitive).
    Yeah, I got that. Just picking nits there. For the lulz.

    Quote Originally Posted by siteguru View Post
    Assuming it's coming from a database, and assuming you're trying to do this without reloading the page each time....
    The thread title and the OP's pseudocode suggest that this is the case.

    Quote Originally Posted by siteguru View Post
    1. Get all possible data options from the database and store in Javascript arrays.

    2. Get the first set of data (for the 1st combobox), then when a selection is made use AJAX (XMLHttpRequest) to get the data for the 2nd combobox and populate it, then repeat as needed for subsequent lists.

    I suggest you search for dynamic dropdown lists.
    Most "copy and paste" JavaScripts of this type use the first approach. The array required to hold 100+ countries and all of their major cities would be very large indeed. Therefore, I recommend the second approach. Here is a PHP/AJAX solution to the OP's specific problem:

    http://satya61229.blogspot.com/2007/...t-list-by.html

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @siteguru
    thx for your reply. but i dont like arrays also i dont wanna to use arrays.)

    @World Wide Weird
    thx for your ways.

    i understand that. i cant do it with vbscript . i dont know java and ajax also.

    thx 2 all

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    So what you want is an ajax-powered dynamically populated select list, with Country populating Cities, and Cities populating Area

    Here is a demo that does it for Country and Area, that shouldn't be too difficult to extend to your intentions.

    http://www.noboxmedia.com/demos/AJAX...list/index.php
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •