Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // form view
- <form autocomplete="off">
- <?= csrf_field(); ?>
- <div class="card-body">
- <div class="row">
- <div class="col-md-2">
- <div class="form-group">
- <label for="fromDate">From Date:</label>
- <div class="input-group date">
- <input type="hidden" class="txt_csrfname" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" />
- <input type="text" class="form-control datepicker" id="fromDate" name="fromDate">
- <div class="input-group-addon">
- <span class="glyphicon glyphicon-th"></span>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-2">
- <div class="form-group">
- <label for="toDate">To Date:</label>
- <div class="input-group date">
- <input type="text" class="form-control datepicker" id="toDate" name="toDate">
- <div class="input-group-addon">
- <span class="glyphicon glyphicon-th"></span>
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-3">
- <div class="form-group">
- <label for=""><font color="white"> _</font></label>
- <div class="input-group">
- <button type="submit" id="submit" name="submit" value="search" class="btn btn-primary col-sm-3">Search</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- //controller
- public function searchData()
- {
- $fromDate = $this->request->getVar('fromDate');
- $toDate = $this->request->getVar('toDate');
- $query = $this->db->table('tb_cek_harian')->getWhere(['ch_delivery >=' => $fromDate, 'ch_delivery <=' => $toDate]);
- $data = $query->getResult();
- var_dump($data);
- echo json_encode($data);
- }
- // ajax
- //button search
- $('#submit').on('click', function(){
- event.preventDefault();
- var table = $('checksheet');
- // var fromDate = document.getElementById("fromDate").value;
- // var toDate = document.getElementById("toDate").value;
- var fromDate = $("#fromDate").val();
- var toDate = $("#toDate").val();
- var x = 1;
- if(fromDate == ''){
- error_firstname = 'please enter start date';
- alert(error_firstname);
- }
- else if(toDate == ''){
- error_lastname = 'please enter end date';
- alert(error_lastname);
- }
- else{
- console.log(fromDate);
- console.log(toDate);
- $.ajax({
- url: "<?php echo base_url('/checksheet/search'); ?>",
- type: 'POST',
- dataType: 'JSON',
- data: {
- fromDate:fromDate, toDate:toDate
- },
- success: function(data) {
- console.log(data);
- var html = '';
- var i;
- for(i=0; i<data.length; i++){
- html += '<tr>'+
- '<td style="text-align:center;">'+data[i].ch_name+'</td>'+
- '<td style="text-align:center;">'+data[i].ch_lot+'</td>'+
- '<td style="text-align:center;">'+data[i].ch_delivery+'</td>'+
- '<td style="text-align:center;">'+data[i].ch_result+'</td>'+
- '</tr>';
- }
- $('#listRecord').html(html);
- },
- error: function(xhr, textStatus, error) {
- console.log(xhr.statusText);
- console.log(textStatus);
- console.log(error);
- }
- });*/
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement