Welcome Guest, Not a member yet? Register   Sign In
two combobox with ajax or javascript

Hi, I have 2 combobox in my view. that is 1.country, 2.Zone.
My problem is, when I select the country in a 1st combobox the proper zone should generate in a 2nd combobox dynamically. I was done it using php and ajax. But I don't know how to do these things in codeigniter. If any one know please help me.
Thank You.

It works just the same.

Imagine you use following jQuery code:

$('#country').change(function() {
  var countryID = $(this).val();
    url: '/controller/ajaxmethod',
    data: 'countryID='+countryID,
    type: 'POST',
    success: function(returnData) {
This code basically just calls http://www.example.com/controller/ajaxmethod, sends some POST data (GET won't work unless you configure CI so). And replaces the zone combo box's html with the html returned by your method.

This method, in your 'controller' controller, could look like this:
function ajaxmethod() {
  $countryID = $_POST['countryID'];
  $query = $this->db->get_where('zones', array('countryID' => $countryID));
  foreach($query->results() as $row) {
    echo "<option value="{$row->zoneID}">{$row->zoneName}</option>\n";

Bramme, Thanks for you replay, I did not try to use jQuery. but I was try using ajax with codeigniter. it's getting follownig error,
"There was a problem while using XMLHTTP:Not Found"
How can I solve this.
Please help me.

Hi,All Please Help me,I am in a problem above Question.
Thank You.

Hi, Bramme, Can you post all the code you post above.
Thank You.

Theme © iAndrew 2016 - Forum software by © MyBB