Welcome Guest, Not a member yet? Register   Sign In
Values from textbox array not updating
#1

(This post was last modified: 02-27-2019, 11:46 PM by zeus2026.)

Hi guys, Im new in this forum and i'm having a hard time updating selected value from checkbox coming from the textbox value. 

Scenraio:

I want to update selected items, For example I want to update Item-2 and the textbox from item recieve will be enable, I will enter a number for example 1 and the textbox from total receive will automatically sum using ajax.

The problem is after submiting the value from total recieve the records that was updating is blank, but when I try to check and print_r the value is there.

And one more thing if all checkbox are all checked and enter a number for each item recieve, the value that it only get is the last value and will be updated will all selected checkbox.

Note: 
Checkbox is an array
Textbox from total recieve is an array


Can you guys please help me?

Here's my UI:

[Image: w5jkp.jpg]

Here's my code.

Controller:
Code:
public function recitem_insert(){

$this->load->model('dbquery');    

$check = $this->input->post('check');    
$total_rec = $_POST['total_rec'];

    
if(isset($check)){ //Check if check is checked    
        
  for($i=0;$i<sizeof($check);$i++){
    for($j=0;$j<sizeof($total_rec);$j++){    

    $updateData = array('rec_qty' => $total_rec[$j] );                                                        
    $this->dbquery->modUpdatedynamicval('tblstock', 'id', $updateData, $check[$i]);

       }        
   }//end for loop    

    echo "<script type='text/javascript'>
        alert('Successfully Added!');
        window.close();
        </script>";        
    
}else{ //End If
      echo 'Please select a checkbox';
    }

}


View:

Code:
<form method="post" action="<?php echo base_url() ?>user/recitem_insert">

<div class="box">
<div class="box-header">
<h3 class="box-title">System ID: <b><?php echo $process_id; ?></b></h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Action</th>
<th>Item Code</th>
<th>Item Description</th>
<th>Required QTY Order</th>
<th>Last QTY Recieve</th>
<th>Item Recieve</th>
<th>Total Recieve</th>



</tr>
</thead>
<tbody>

<?php                  

$query = $this->db->query("SELECT * FROM tblstock where process_id = '$process_id'");
foreach ($query->result() as $row){                                      
?>  

<tr>
<td><input type="checkbox" name="check[]" id="opt" value="<?php echo $row->id; ?>" onclick="valueChanged()"> </td>
<td><?php echo $row->item_code; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->qty_order; ?></td>
<td><?php echo $row->rec_qty; ?></td>

<input type="hidden" name="last_item_rec[]"  value="<?php echo $row->rec_qty;  ?>">

<td><input type="text" name="item_rec[]"  id="txt" disabled=""></td>  
<td><input type="text" name="total_rec[]"></td>  


</tr>

<?php

}
?>  

</tbody>
<tfoot>

</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>

<div class="box-footer">
<button type="submit" class="btn bg-olive btn-flat margin">Submit</button>
</div>

</form>


Model:

Code:
public function modUpdatedynamicval($table, $column, $data, $equal_to){
        
$this->db->where($column, $equal_to);
$this->db->update($table, $data);         
    
}


Any help will be gladly appreciate.


Thank you..





EDIT:

Lets assume, I've input 1 in item_receive textbox one and the total recieve will be 10, 2 in item_receive textbox two and the total recieve will be 11, 3 in item_receive textbox three and the total recieve will be 12,

[Image: yngJo.jpg]


CODE:

Code:
$check = $this->input->post('check');  
$total_rec = $_POST['total_rec'];

echo 'Check Value';
print_r($check);

echo '<br><br>';

echo 'Total Recieve';
print_r($total_rec);

OUTPUT:

Code:
Check ValueArray ( [0] => 1 [1] => 2 [2] => 3 )

Total RecieveArray ( [0] => 10 [1] => 11 [2] => 12 )



But If I only inout the second textbox here's the output:

Code:
Check ValueArray ( [0] => 2 )

Total RecieveArray ( [0] => [1] => 11 [2] => )
Reply
#2

Please help... T_____T
Reply




Theme © iAndrew 2016 - Forum software by © MyBB