How to do jquery/ajax partial post after on change event of dropdown

How to to ajax/jquery post on on change event of drop box in php :
I m Using Codeignitor /Grocery Crud framework .

I want to render the same form  having depended dropbox

dropbox1-->  value -->dropbox2 (where clause)

Select value from dropbox1 and create dropbox2 based on parent dropbox1
Puneet AroraFounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
I covered this dropdown list dependency here:

http://www.experts-exchange.com/questions/28699276/How-to-create-php-variable-from-the-selected-value-of-a-dropdown.html#a40893639

It should help you do the front-end (binding a function to the first dropdown, emitting an POST ajax request upon change, grabbing the result and then populate the second/dependent dropdown).  Notice that on the backend the poster is sending a json-encoded string with a key/property named "options" which contains the <option> tags for the second <select>.
Puneet AroraFounderAuthor Commented:
Dear hielo ,

I have checked the comments for right solution  , And found that I m doing similar to
what you are suggesting ...!  But I found difference in the ajax syntax , so here it is :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
      alert('Entered the Ready Function');
      //event.preventDefault();
      $('#country').change(function(){
                  alert('Entered Chnage Function');
            var country_id = $('#country').val();
            if(country_id != 0)
            {
            
                  alert(country_id);
      
                  $.ajax({
                        type:'post',
                        url:'getvalue.php',
                        data:{"id":country_id},
                        cache:false,
                        success: function(returndata){
                               $('#city').html(returndata);
                        }
                  });
            }
      })
})


I also found that it is giving me status OK 200 using FireBug, and finds the controller "getValue.php" , But I
want the selected value /id to be printed/echo also on  getValue.php and then
the child dropdown renders on from where the post was made .. The getValue is
not echo or printing any value ..? I don't know  why ? I m using Codeignitor /Grocery  Frameworks
hieloCommented:
Look at my second post on the link above.  That is basically what you need in getValue.php -- query the db; dynamically create the html <option> tags while iterating over the records; echo the result of jason_encode.  Basically all you need to change are the db connection credentials (on that post it is understood that these are in db.php) and the select query.

>> I also found that it is giving me status OK 200 using FireBug
Are you referring to the ajax call or the loading page?

>>But I want the selected value /id to be printed/echo also on  getValue.php
But if you are emitting an ajax call, the "current" page never changes.  So the country_id you are sending to the server (via ajax) should still be on the browser window -- you shouldn't have to echo it back.

It would help if you post a link to a "test page".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Puneet AroraFounderAuthor Commented:
Now , it is working : ajax call
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.