Nested Ajax Calls with PHP/MySql

Discussion in 'Programming' started by coldfire7, Mar 29, 2009.

  1. #1
    hello guys,

    i hope everyone reader has abit know how of ajax.

    I am stuck at the position where I am trying to do nested ajax calls.

    The scenario is:
    My main page has an iframe, which loads the content (dozen of drop down lists) through ajax, and than at one of the Lists i have an onchange event which again loads a <div> through ajax.

    The second ajax call doesnt seem to work after such a long time.

    One more question regarding this,

    How can I get the value of selected option of the deop-down list which is loaded through ajax call ?

    thanks
     
    coldfire7, Mar 29, 2009 IP
  2. kindy

    kindy Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do you mean you need to call from an array?
     
    kindy, Mar 29, 2009 IP
  3. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I mean to call from an onchange event of Dropdown list which is itself generated through Ajax.

    Lets suppose,
    The First List is of Countries

    List1:

    Albania,
    Croatia,
    ,....
    USA,
    Zimbabwe


    On selecting any country, the ajax call will return another set of lists e.g.

    State/City, ZipCode, Address ,etc.
    Lets say, it returns 2 lists, call them List 2 & List 3

    List2:
    California,
    Denver,
    NewYork
    ...
    List 3:
    1234,
    5678,
    3153,
    ...

    When I select California, I need to trigger an ajax call to load something else, but here, the <select onchange=jsFUNCTION(this.value)><option></></>
    onchange function is not triggered to call the js function.

    I want to get the value of List2 selection, either I can use ajax, or assign the selection value to a hidden field. But both doesnt seem to work.


    If I assign the value of List2 selected-index to a hidden field at the same page, the parent page, couldnot retrieve it using php POST variable e.g.
    <input class="Hidden" id="hiddentext" value="" >
    JS(){
    // hiddentext.value = list.option.value
    }

    <?php

    $value = $_POST['hiddentext']; //it doesnt retreive the right value

    ?>
     
    coldfire7, Mar 30, 2009 IP
  4. joep1978

    joep1978 Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Using a hidden field is the right way to do it - I've done this before and it works fine for me - it sounds like you may not be referencing your elements correctly. I normally pass the value to onchange doing:-

    onchange="javascript:updateField(options[selectedIndex].value);"

    Then for the function I do something like

    function updateField(p_selected_value)
    {
    var hiddenbox = document.getElementById('hiddentext').value;
    hiddenbox.value=p_selected_value;
    }
     
    joep1978, Mar 30, 2009 IP
  5. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes, i have solved the problem using hidden fields as u mentioned above. BUT, its not the right way, as i have lots of fields which I will be retrieving using hidden fields. And it will make the whoe page slow.....

    any fast solution if this kind of problem appears and u have a lot of fields to get their value !!!
     
    coldfire7, Mar 30, 2009 IP
  6. joep1978

    joep1978 Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    why does it make the page slow? how many fields are we talking about? it's just setting a variable - it's not an intensive process
     
    joep1978, Mar 30, 2009 IP
  7. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i have 30 to 40 fields for which i need the value like this...so i have to make 30-40 hidden text fields, which will load and get hidden. so making an overhead....i am updating the values of these fields on a single function...anyway....as long as its working its fine!!! :D
     
    coldfire7, Mar 30, 2009 IP
  8. joep1978

    joep1978 Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    the only way i can think of doing it without creating those hidden fields is to loop through all the fields and create a big string of ?var1=val1&var2=val2&... and append that string to the form action url via GET, but then you will have this data showing up on the browser bar after the user submits.
     
    joep1978, Mar 30, 2009 IP