Ajax question, multiple fields...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • panos100m
    New Member
    • Aug 2007
    • 23

    Ajax question, multiple fields...

    Hi there our developer is creating a website in Ajax.

    In one page we have the following fields.

    Country:

    City/State:

    International Code:

    We requested for him that when the country is selected then the city and international code to be updated automatically ...

    He implemented that for the city but he says that he cant do it for both ..and that in ajax you can call only one page at the time ..

    so essentially he says that i have to choose only one field either city to be populated automatically when i select the country or int code but not both...

    Is there a way to overcome this limitation ?

    Can you please provide me with a small snippet of code of how this can be done .?

    Thank You
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    welcome to TSDN ...

    it is not quite clear to me what the problem really would be. could you explain the dependencies in more detail? what would you expect when you choose a country ... please give a textual example. besides that ... when there are no logical restrictions you may call as much dependend data as you want with ajax ... so please give the example.

    kind regards

    Comment

    • panos100m
      New Member
      • Aug 2007
      • 23

      #3
      Hi and thanks for welcoming me all of the fields are dropdown except the int code which is an edit box ..

      Country(dropdow n)

      Citry (dropdown)

      Int Code [edit box]

      When country is selected e.g UK i would like to get the avalable cities e.g
      London , Bedford , Oxford etc in the city field ..

      and also in the int code to get the code 0044

      If usa is selected i would like to get all the state names in city (i would actually like the text also to change to state)

      and the int code to be 001 .

      I am not sure about what the restrictions are but our developer says that this is nto possible to be done for both ....

      I can get back to you with more info if needed .

      Thanks again :-)

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        ok ... in case he says so ... it must have other reasons than the dependency logic ... let me give you an idea:

        you choose UK ... send the request to the server and you do two things:

        1. select all cities for UK
        2. select the int_code for UK

        put it in a response-string (probably json/xml) and send it back to the client that evals it and may populate the two fields with the received data.

        even when there is only a restriction to make one call (for any reason) you may handle it as follows:

        1. select all cities for UK

        send back the response ... process it as shown ... and simultanuosly send the next request:

        2. select the int_code for UK

        get the response and process step two ...

        kind regards

        Comment

        • markrawlingson
          Recognized Expert Contributor
          • Aug 2007
          • 346

          #5
          He can parse this data on 1 page and does not need 2.

          When a country is selected, and he subsequently calls the server page - he can generate the drop down content for the citities, and attach the int code at the beginning.

          like so...

          [CODE=asp]
          <%
          Response.write intCode& " " & sCityList
          %>
          [/CODE]

          The intCode as well as the list of cities will be returned to the first page, with the intCode attached to the first. Then all you have to do is parse the data. Namely, to split the data.

          [CODE=javascript]
          var response = http.responseTe xt
          var response = response.split( " ")
          //response should now be an array containing the int code at index 0
          document.getEle mentById("yourI ntbox").value = response(0)
          [/CODE]

          I used this method similarly 6 months ago to create an input system where a user could input a pre-dinfed 6 digit hex code, and onkeyup, if the key was found - it would locate their information in a database, and automatically fill out an entire registration form for them, including over 20 fields.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Panos. Welcome to TSDN!

            You can send as many AJAX requests as you'd like. You can even have more than one active AJAX request at any given time.

            I'm not sure what your developer is talking about. Perhaps he is mistaken, or perhaps the way he implemented it, you can't run more than one AJAX call per page load (in which case, I'd get on him to find out how to fix that!).

            Comment

            Working...