Web Analytics Made Easy -
StatCounter AJAX/DOM problem - CodingForum

Announcement

Collapse
No announcement yet.

AJAX/DOM problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX/DOM problem

    I use AJAX to populate sequentially some list boxex onchange (onchange first list will request data then will populate the second list, onchange the second list will populate the third list, and so on...)

    It works, but I need also to do the same in a single process onload, and here it comes the problem:

    the operations sequence is:

    I have the list of selectedIndexes for all the lists via a php aplication

    onload = function(){

    - get the list 1 selectedIndex (previousely php generated)
    - set the selected option
    - send a request based on the selectedIndex
    - get the responseText string separated by a separator, split the string
    - use DOM to create the list 2 options
    ------------
    - get the list 2 selectedIndex (previousely php generated)
    - set the selected option
    - send a request based on the selectedIndex
    - get the responseText string separated by a separator, split the string
    - use DOM to create the list 3 options

    ----------
    }

    The problem is that it does not work at all, unless I insert some alerts here and there, for instance after the DOM appends the set of options for each list.

    When I hold the code with alerts, it works OK. When I remove the alerts, it does not work at all. I tried some setTimeout(), but with no succes.

    Does anyone of you had the same problem? I can not set a single request, as I don't know, on each step, which will be the response content of the next step (the request is made to a DB, via a php file)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    You are doing this to set defaults when the user comes back to the form? When I see this I wonder why don;t you just do it to start out with with your page as it is being rendered from the server. Have the server fill out the form if there are variables. Makes it easier and the user does not have to wait for their form to fill in after it loads.

    (Not sure if that made sense)

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      Maybe I don't understand, at the initial request you get the data that you send in the second request, since you are the one filling in the data that provides the data for the second request, what is preventing you from just knowing what it's (the second select or third for that matter) selected index will be once you fill in it's parameters, but prior to doing so. . .man now I've confused myself. It just sounds like you need to re-think how the page you are posting to handles the initial request, so that it queries out to the last select before it comes back. Or don't actually create or fill in the select boxes until you have the data to fill all three of them.
      Last edited by Basscyst; Sep 29, 2006, 02:54 PM.
      Helping to build a bigger box. - Adam Matthews

      Comment


      • #4
        I decided to try the variants;
        1. - use a multiple request (which will make my php programmer unhappy, as he must rethink it's application)
        2. - use a different javascript function and a different php file - as by now I tried to use the same one used for onchange event (which will make... as above... )
        3. - use a synchronous requests (that means in fact to use the 2. variant which will make ... as the above's above )
        4. - forget about it and tell the client that it does not worth (which will make the client unhappy, but my php programmer will be happy... I don't know which of them worths )

        Thank u all for your thoughts, there were very useful for me, indeed !
        KOR
        Offshore programming
        -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

        Comment

        Working...
        X