html - autocomplete by jquery in codeigniter textbox id not working -
i creating form in table , 1 add button ,one delete button , 1 submit button.
when click add button 1 row created , when click delete button 1 row goes deleted.
here view page
<div style="overflow: scroll;"> <?php $attributes = array('class' => 'form-horizontal', 'id' => 'form'); echo form_open('digital/add_task', $attributes); ?> <table class="table" id="datatable"> <thead> <tr> <th>select</th> <!--<th>date</th>--> <th>types of work</th> <th>worked with</th> <th>director</th> <th>no of hours</th> <th>task</th> <th>task status</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" name="chk"/></td> <!-- <td><input type="text" name="date[]" value="" /></td>--> <td><input type="text" name="work[]" value="" id="task" /> <span class="text-danger"><?php echo form_error('work[]'); ?></span> </td> <td><input type="text" name="partner[]" value="" /> <span class="text-danger"><?php echo form_error('partner[]'); ?></span> </td> <td> <select name="director[]"> <option value="hkn">hkn</option> <option value="anita">anita</option> <option value="ravi">ravi</option> <option value="ameesha">ameesha</option> </select> <span class="text-danger"><?php echo form_error('director[]'); ?></span> </td> <td><input type="text" name="time[]" value="" /> <span class="text-danger"><?php echo form_error('time[]'); ?></span> </td> <td><input type="text" name="task[]" value="" /> <span class="text-danger"><?php echo form_error('task[]'); ?></span> </td> <td><input type="text" name="status[]" value="" /> <span class="text-danger"><?php echo form_error('status[]'); ?></span> </td> </tr> </tbody> </table> <input class="btn btn-primary" type="button" value="add row" onclick="addrow('datatable')" /> <input class="btn btn-primary" type="button" value="delete row" onclick="deleterow('datatable')" /> <input class="btn btn-primary" type="submit" name="submit" value="submit"> <?php echo form_close(); ?>
here model:
public function search_task($qs) { /* comparing data text box */ $query = $this->db->query("select work_name task_name work_name ('$qs%') order work_name limit 5"); /* checks row in database table */ if ($query->num_rows > 0) { foreach ($query->result_array() $row) { $row_set[] = htmlentities(stripslashes($row['work_name'])); } echo json_encode($row_set); } }
here controller:
public function task_search() { if (!isset($_get['term'])) { exit; } $qs = strtolower($this->input->get('term')); $this->digital_hodm_model->search_task($qs); }
here jquery file:
<script language="javascript"> function addrow(tableid) { var table = document.getelementbyid(tableid); var rowcount = table.rows.length; var row = table.insertrow(rowcount); var colcount = table.rows[1].cells.length; for(var i=0; i<colcount; i++) { var newcell = row.insertcell(i); newcell.innerhtml = table.rows[1].cells[i].innerhtml; //alert(newcell.childnodes); switch(newcell.childnodes[0].type) { case "text": newcell.childnodes[0].value = ""; break; case "checkbox": newcell.childnodes[0].checked = false; break; case "select-one": newcell.childnodes[0].selectedindex = 0; break; } } } function deleterow(tableid) { try { var table = document.getelementbyid(tableid); var rowcount = table.rows.length; for(var i=0; i<rowcount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childnodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowcount <= 2) { alert("cannot delete rows."); break; } table.deleterow(i); rowcount--; i--; } } }catch(e) { alert(e); } } </script> <!-- javascript used autocomplete search through database--> <script type="text/javascript"> $(function(){ $("#task").autocomplete({ source: "<?php echo base_url();?>digital/task_search" // path task_search method }); }); </script>
my first default row of table selected autocomplete text database when type in types of work text box when add 1 row click add button in types of work field when type auto complete text not selected.
please me find solution
you calling autocomplete function on $("#task"). first element id gets autocomplete feature. rest ignored. either add class elements , can call autocomplete on class :
$(".someclass").autocomplete({ source: "<?php echo base_url();?>digital/task_search" // path task_search method }); });
or need add id new cell generated jquery. use
jquery(this).attr("id","newid");
Comments
Post a Comment