1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Question - ASP + Ajax

Discussion in 'C#' started by cancer10, May 14, 2007.

  1. #1
    Question - ASP + Ajax

    Hey!
    SEMrush
    Not sure if this is the correct section to post this. ;)

    Well, I have a table in my sql server 2000 database

    ***************
    tblAddress
    ----------------------------
    City_Name (varchar)
    Venue_Name (varchar)
    *******************

    The "City_Name" column contains all the name of the cities in my country and each city has multiple venues.

    Now I have 2 drop-down boxes in my asp page. The first drop-down is already listed with all the cities which are in the "City_Name" column.

    What I now want is, when I select a city name from the first drop-down, the second drop down should be populated with all the venue names of that city (of course without refreshing the page)

    I know this can be done with ajax.

    I got few codes while googling but none of them are working :(
     
    cancer10, May 14, 2007 IP
    SEMrush
  2. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you using asp.net, or classic?

    If .NET go and the AJAX sdk from www.asp.net, it makes this stuff soooooo easy even I can do it.

    Jay
     
    jaymcc, May 14, 2007 IP
  3. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i m using classic asp
     
    cancer10, May 14, 2007 IP
  4. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's possible in ASP, but considerable work. I would have a look at learnasp.com, i think there is an article there about doing something similar to this.
     
    jaymcc, May 14, 2007 IP
  5. VishalVasani

    VishalVasani Peon

    Messages:
    560
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hello,

    I have develop similar thing in asp & ajax. If you want can help you PM me the details of your table(full tabel details)....I will return you the code....
     
    VishalVasani, May 14, 2007 IP
  6. Aztral

    Aztral Well-Known Member

    Messages:
    344
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    125
    #6
    You just wanna call a js function from onchange() for the City_Name drop-down.

    In that function get City_Name.value and use ajax to pass it to an asp with City_Name.value as a parameter like "getvenue.asp?city=" + City_Name.value

    Use Request.QueryString("city") to get the city in the ASP file. Use that value to generate a query, something like....
    Dim sSql
    sSql = "SELECT * FROM venues WHERE city='" & Request.QueryString("city") & "';"

    Then you can loop over your recordset and spit out the html for your second drop down...

    response.write "<select name='venue'>"
    oRS.MoveFirst()
    Do While oRS.EOF = False
    response.write "<option value='" & oRS("venue") & "' selected>" & oRS("venue") & "</option>"

    Loop
    response.write "</select>"


    Then,

    in your html code put a wrapper div around where you want your second drop-down to go and give an id. say...'venue'

    Lastly in the callback you specified for your xmlobject (you did set a callaback function and use "GET" as a parameter?) just do some javascript like
    if (xmlHttp.readyState==4)
    {
    GetElementById(''venue'').innerHTML= xmlHttp.responseText;
    xmlHttp=null;
    }

    And Tada!

    You can create a server-side to create xml right from query using MSXML.DOMDocument. And output that.
    then in your javascript callback function use

    var xmldoc = xmlHttp2.responseXML; // notice the use of responseXML
    and parse as xml.
     
    Aztral, May 16, 2007 IP