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

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

[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.
#4

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

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




Theme © iAndrew 2016 - Forum software by © MyBB