When I try to alert the item_id
after giving input in the quantity textbox, I am receiving an undefined JavaScript alert. The code snippet below is not displaying the alert as expected:
var item_id=$("#item_"+i).val();alert(item_id);
In addition, my model and controller are not displaying the item properly. Can someone please assist me with this issue?
This is how my view looks like:
<td style='width:20%' id='producttd_1'>
<select name='item[]' id='item_1' class="form-control selectpicker" style='width:100%' data-show-subtext="true" data-live-search="true" >
<?php
if(!empty($prolist))
{
print_r($prolist);
foreach($prolist as $pro)
{
$opn1.="<option value='".$pro['id']."'>".$pro['product_name']."</option>";
}
}
?>
</select>
</td>
<td style='width:7%'><input type='text' name='nos[]' id='nos_1' class="form-control" style='width:100%'/></td>
<td style='width:7%'><input type='text' name='quantity[]' id='quantity_1' class="form-control addrow quantity" style='width:100%' onKeyup='calc(1);'/></td>
<td style='width:7%'><input type='text' name='rate[]' id='rate_1' class="form-control addrow" style='width:100%' onKeyup='calc(1);'/></td>
Below is the relevant AJAX code:
function calc(i)
{
if(event.keyCode == 13) {
add_row();
}
else
{
var item_id=$("#item_"+i).val();
alert(item_id);
var rate=$("#rate_"+i).val();
// Other code logic goes here...
}
}
And here's my controller snippet:
function product_det()
{
$item=$this->input->post('item_id');
echo $item;
// More code for processing product details...
}
Finally, this is my model function for fetching product details:
function get_productDet($item)
{
$this->db->select('*');
$this->db->from('product');
$this->db->where('id',$item);
$res=$this->db->get()->row_array();
return $res;
}