• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repopulate Autoload Dropdown value With Ajax/Jquery

I have spent 2 days on this and I am reaching nowhere. I am a new learner and as encouraged by forum members in one of my other post I am using this forum to get hand on CI.

I am new to php and CI. I have this strange problem here. I am able to repopulate dropdown field value upon error on the first dropdown field only because the values for first field are being pulled from "view.php". I also posted this question on stackoverflow but no response Link Here

I have model:

function getCountry(){
   $this->db->order_by('v_country_name', 'asc');
   return $query;
function getData($loadType,$loadId){
   if($loadType=="state") {
       $fieldList='id,v_state_name as name';
   } else if ($loadType == "region") {
       $fieldList='id,v_state_region_name as name';
   } else {
       $fieldList='id,v_city_name as name';
   $this->db->where($fieldName, $loadId);
   $this->db->order_by($orderByField, 'asc');
   return $query;

And a controller dashboard.php

public function loadData()


   if($result->num_rows() > 0){
       foreach($result->result() as $list){
           $HTML.="<option value='".$list->id."'>".$list->name."</option>";
   echo $HTML;

And View:

<?php if($list->num_rows() > 0){ ?>

<select class="full-width" name="v_item_country" onchange="selectState(this.options[this.selectedIndex].value)">
<option value="0">Country</option>
   <?php foreach($list->result() as $listElement): ?>
       <option value="<?= $listElement->v_country_id?>" <?php if($this->session->flashdata('v_item_country') === $listElement->v_country_id) echo('selected')?>><?= $listElement->v_country_name?></option>
   <?php endforeach; ?>

<select class="full-width" name="v_item_state" id="state_dropdown" onchange="selectRegion(this.options[this.selectedIndex].value)">
   <option value="0">State</option>

<select class="full-width" name="v_item_city" id="city_dropdown">
   <option value="0">City</option>

<?php }else{ echo 'No Country Name Found'; } ?>

And I am totaly lost about ajax.jquery.


Messages In This Thread
Repopulate Autoload Dropdown value With Ajax/Jquery - by Codeigniter_Learner - 12-27-2015, 06:41 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.