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

[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";
  }
}


Messages In This Thread
two combobox with ajax or javascript - by El Forum - 08-25-2010, 12:55 AM
two combobox with ajax or javascript - by El Forum - 08-25-2010, 01:38 AM
two combobox with ajax or javascript - by El Forum - 08-26-2010, 01:00 AM
two combobox with ajax or javascript - by El Forum - 08-31-2010, 04:24 AM
two combobox with ajax or javascript - by El Forum - 08-31-2010, 09:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB