0

これは私のビューコードです

<input type="text" name="chname" id="chrname" placeholder="church name" />

これは私のコントローラーコードです

function auto_comp(){
   $q = strtolower($_GET["q"]);
    if(!$q) return;
    $res=$this->churchmodel->auto_compt($q);
    if($res){
      foreach($res as $row){
        //echo row->chid;echo "<input type=\"text\" value=\"".$row->chid."\" />";echo row->churchname."\n"; 
      }
    }
  }

これは私のモデルコードです

function auto_compt($name){
$val="%".$name."%";
$query=$this->db->query("select distinct name as churchname, id as chid from church where name like '$val'");
if($query->num_rows>0){
    return $query->result();
}else{
    return false;
}
}

jqueryコード

 $().ready(function() {
  $("#chrname").autocomplete("localhost/deeps/genting/index.php/church/auto_comp", {
     width: 260,
     matchContains: true,
     selectFirst: false
  });  
 });

ここでは完全に機能していますが、選択した値のIDを簡単に保存できるように、特定の選択で対応するIDを取得する必要があります。事前に感謝を助けてください

4

1 に答える 1

0
 $(document).ready(function() {
  $("#chrname").autocomplete("localhost/deeps/genting/index.php/church/auto_comp", {
  width: 260,
  matchContains: true,
  selectFirst: false,
  select: function (event) {
   alert(event.target.id)   // fetch your id here
  }
 });  
});
于 2013-10-18T06:18:51.693 に答える