1

How can I call all the data of id=1 in all those input box from db

this is the form need to call the data of id=1 to all those text box

How can I call all the data of id=1 in all the input box from db?

<form role="form" class="form-horizontal" action="<?php echo base_url();?>ForceAttendance/saveForceAttendance" method="post">
    <fieldset> 
        <div class="form-group">
            <div class="col-md-12">
                <label class="control-label col-md-2">Employee ID</label>
                <div class="col-md-2">
                    <input id="id" type="text" name="emp_id" class="form-control" value="" required>
                </div>
            </div>                                          
        </div>

        <div class="form-group">
            <div class="col-md-12">
                <label class="control-label col-md-2">Employee name</label>
                <div class="col-md-5">
                    <input type="text" name="emp_name" class="form-control" value="" required>
                </div>                                          
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-12">
                <label class="control-label col-md-2">Department</label>
                <div class="col-md-2">
                    <input type="text" name="dep" class="form-control" value="" required>
                </div>                                          
                <label class="control-label col-md-1">Section</label>
                <div class="col-md-2">
                    <input type="text" name="sec" class="form-control" value="" required>
                </div>
            </div>                                          
        </div>

        <div class="form-group">
            <div class="col-md-12">
                <label class="control-label col-md-2">In Remark</label>
                <div class="col-md-2">
                    <input type="text" name="inremark" class="form-control" value="" required>
                </div>                                          
                <label class="control-label col-md-1">Out Remark</label>
                <div class="col-md-2">
                    <input type="text" name="outremark" class="form-control" value="" required>
                </div>
            </div>                                          
        </div>


        <hr/>
        <!-- <div class="col-md-12"> -->
            <div class="col-md-8 col-md-offset-2">
                <div class="col-md-4">
                    <input type="submit" class="btn btn-success col-md-12" name="save" value="Save"/>
                </div>
                <div class="col-md-4">
                    <a href="<?php echo base_url()?>ForceAttendance" class="btn btn-danger col-md-12">Reset</a>
                </div>
            </div>
        <!-- </div> -->
    </fieldset>
</form>

<script type="text/javascript">
$(document).ready(function(){
    $("#id").change(function(){
        //what to do here?

    });
});
</script>
Pang
  • 9,564
  • 146
  • 81
  • 122
  • Read this https://stackoverflow.com/questions/23911438/codeigniter-how-to-get-data-from-database-using-ajax-in-codeigniter – Ukasha May 26 '17 at 04:01

1 Answers1

1

you can try this process

<script type="text/javascript">
    $(document).ready(function(){
        $("#id").change(function(){  
         var id = $('#id').val();
        //check id 
        $.ajax({
            type: 'POST',
            url: "<?php echo base_url();?>controller/method",
            data: {id:id},
            dataType: "JSON",
            success: function(response){
              console.log(response);
              //append 
            }
        });

        });
    });
    </script>

controller

$id = $this->input->post('id');
$resutl = $this->your_model->get_data($id);
echo json_encode(array('data'=>$resutl));
Masud_ma
  • 104
  • 3