CodeIgniter Forums
two combobox with ajax or javascript - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: two combobox with ajax or javascript (/thread-33400.html)



two combobox with ajax or javascript - El Forum - 08-25-2010

[eluser]shahmy[/eluser]
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.


two combobox with ajax or javascript - El Forum - 08-25-2010

[eluser]Bramme[/eluser]
It works just the same.

Imagine you use following jQuery code:

Code:
$('#country').change(function() {
  var countryID = $(this).val();
  $.ajax({
    url: '/controller/ajaxmethod',
    data: 'countryID='+countryID,
    type: 'POST',
    success: function(returnData) {
      $('#zone').html(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:
Code:
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";
  }
}



two combobox with ajax or javascript - El Forum - 08-26-2010

[eluser]shahmy[/eluser]
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.


two combobox with ajax or javascript - El Forum - 08-31-2010

[eluser]shahmy[/eluser]
Hi,All Please Help me,I am in a problem above Question.
Thank You.


two combobox with ajax or javascript - El Forum - 08-31-2010

[eluser]shahmy[/eluser]
Hi, Bramme, Can you post all the code you post above.
Thank You.