Values from textbox array not updating

convert textbox value to array in javascript
how to extract value from array in javascript
how to get array of object values in javascript
fetching array values in javascript
javascript array input value
javascript initialize array with values
store form data in array javascript
how to display array values in node js

I'm new in this forum and I'm having a hard time updating selected value from checkbox coming from the textbox value.

Scenario:

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

The problem is after submitting the value from total receive the records that were updating is blank, but when I try to check and print_r the value is there.

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

Notes:

  • The checkbox is an array
  • Textbox from total receive is an array

Here's my UI:

Controller:

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:

<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:

public function modUpdatedynamicval($table, $column, $data, $equal_to){

$this->db->where($column, $equal_to);
$this->db->update($table, $data);         

}
Edit

Let's assume:

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

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:

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

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

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

Check ValueArray ( [0] => 2 ) 

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

From what I see, you are having a problem to determine which input index is which on the back end. You could set an index key on each of the input like this :

<tbody>

<?php                   

$query = $this->db->query("SELECT * FROM tblstock where process_id = '$process_id'");
foreach ($query->result() as $key => $row){           //added key to be used as inputs key                             
?>  

<tr>
<td><input type="checkbox" name="check[<?php echo $key ?>]" 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[<?php echo $key ?>]"  value="<?php echo $row->rec_qty;  ?>">

<td><input type="text" name="item_rec[<?php echo $key ?>]"  id="txt" disabled=""></td>  
<td><input type="text" name="total_rec[<?php echo $key ?>]"></td>  


</tr>

<?php 

}
?>  

</tbody>

After that, then replace the for loop :

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    

With this foreach :

foreach ($check as $key => $item) {
    $updateData = array('rec_qty' => $total_rec[$key] );                                                        
    $this->dbquery->modUpdatedynamicval('tblstock', 'id', $updateData, $check[$key]);
}

So you don't manually check for the total_rec value but instead it only checks on submitted check post data.

Values from textbox array not updating, 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: MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

from what i can see, like everybody else is saying, you have trouble in finding the correct rows of checked item. I suggest you edit the way you name the form in multidimensional array. bet you didnt know that?

so in view.php

<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                   

//WTF?? it's 2019. Say hello to SQL Injection
$query = $this->db->query("SELECT * FROM tblstock where process_id = '$process_id'");
foreach ($query->result() as $i=>$row){                                       
?>  

<tr>
<td><input type="checkbox" name="data[<?php echo $i;?>][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="data[<?php echo $i;?>][last_item_rec]"  value="<?php echo $row->rec_qty;  ?>">

<td><input type="text" name="data[<?php echo $i;?>][item_rec]"  id="txt" disabled=""></td>  
<td><input type="text" name="data[<?php echo $i;?>][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>

and you can easily cycle through the data for each rows while at the same time validating if the checkbox is checked

 <?php
//simple way of traversing the data
if ( isset( $_POST['data'] ) )
{
    echo '<table>';
    foreach ( $_POST['data'] as $d )
    {
        //you have all the data here
        //start checking on checked box
        if(isset($d['check']))
        {
            echo '<tr>';
            echo '  <td>', $d['last_item_rec'], '</td>';
            echo '  <td>', $d['item_rec'], '</td>';
            echo '  <td>', $d['total_rec'], '</td>';
            echo '</tr>';
        }
    }
    echo '</table>';
}

Values from textbox array not updating, Values from textbox array not updating Im new in this forum and i'm having a hard time updating selected value from checkbox coming from the� Re: Textbox values not updating Jul 01, 2009 12:16 PM | booler | LINK check that you are populating the textboxes inside an If Not Page.IsPostBack block- otherwise you will be overwriting the textbox values each time the page loads. i.e:

Textbox array does not update in a User Control, Hello everyone, I am attempting to build a User Control with a collection of TextBoxes. The idea is to be able to display a collection of� This means if an application has a TextBox with a data-bound TextBox.Text property, the text you type into the TextBox does not update the source until the TextBox loses focus (for instance, when you click away from the TextBox). If you want the source to be updated as you type, set the UpdateSourceTrigger of the binding to PropertyChanged.

Your checkboxes all have the same ID, which always leads to problems. Change the id of the checkbox in the loop.

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

JavaScript array: Add items in a blank array and display the items , Last update on February 26 2020 08:09:06 (UTC/GMT +8 hours) getElementById("text1").value; alert("Element: " + array[x] + " Added at index " + x ); x++; document. It's not: new Number() is not a number, it's an object. So it's working in the sense that the value is correct and the text box is populated but when i update the quantity field the value is not changing. I'm sure I'm missing something obvious but as JavaScript is new to me I can't spot it. Edit. Here is a sample of the whole table, form and JavaScript code:

ObjectDataSource.Update Method (System.Web.UI.WebControls , A value that represents the number of rows updated in the underlying data storage. TextBox controls, and several ObjectDataSource objects to update data. NET Web pages validate that user input does not include script or HTML elements. static ICollection GetAllEmployees () { ArrayList al = new ArrayList(); // Use the� Hi all, I have tried all the suggestion here but unfortunately my update still does not work. When I went to view page source, the value of being updated is being stored in an array but unfortunately it does not retain the updated value in the form as well as in the database.

How works event.target.value? - JavaScript, This is the part where the users input should update the input key in your state. You are getting the value from the input textbox but it is not updating the input key in� Using arrays. 12/26/2018; 2 minutes to read; In this article. You can declare an array to work with a set of values of the same data type.An array is a single variable with many compartments to store values, while a typical variable has only one storage compartment in which it can store only one value.

Value Binding | Kendo UI MVVM, If the View-Model value is updated from code, then the value of the bound DOM DateTimePicker, Editor, MaskedTextBox, MultiSelect, NumericTextBox, Slider, its value , or text content if the value is not set, to the selectedColors array. The field on SP is a text field because the reference list (Rates list) resides on a different site. I've created lookups before w text fields but only for single values. This was my first attempt to try to do a multivalue combobox w a text field as the base, maybe it can't be done. I did try the combobox.selecteditems.rate but it says its not

Comments
  • If you are using Ajax than add it your code
  • But I need this in normal submit.. :(
  • what is value After submitting array?
  • if checkbox 1 is selected the value submiited is blank, checkbox 2 also blank but if checbox 3 give a correct value submitted.
  • So, Can you please share your full code and table structure
  • Your code seems like the output will be the same in my question code. If I input a value for example I input 2 in all textbox and tried to print_r, these are the output Array ( [0] => 2 [1] => 2 [2] => 2 ), But if I skip the first textbox and input the second and third checkbox here's the output Array ( [0] => [1] => 2 [2] => 2 ), the first array values are blank, then I f i try to update in query the data that will be pass is also blank.
  • @zeus2026 yes it's still passing the empty total_rec arrays to the back end, but if you are using the foreach $check, it will only pass the total_rec with values, so the modUpdatedynamicval function will not get any empty total_rec
  • I have tested using the nested for loop just like on your question, and that's the cause of why you only get the last input values when updating the data. Do you want to update the total_rec value on unchecked box as well? or do you want to update only the checked boxes?
  • I tried this but it only get the last value of the array.
  • If you select all checkbox than you get all value and you select one then get one value
  • Have you got your answer?