php - Changing a specific span tags value with Jquery, codeignighter -
i have form contains table 3 inputs, , 1 span in each row. first input product name. when fill out , looses focus using ajax post function quantity have on hand. need place value span. thing there can upwards of 100 of these rows added dynamically have tried using .next() (
here jquery.
$( document ).ready(function () { // set on click on button $('input[id^="products"]').blur(function () { var productname = $(this).val(); $.ajax({ type: "post", url: "<?php echo site_url('autocomplete/get_info'); ?>", datatype: "json", data: {productname:productname}, success: function(msg){ $('span[id^="qoh"]').html(msg); } }); }); }); here form , table creation codeignighter
<?php echo form_open('transactions/transaction_review'); ?> <div class="form_settings"> <p><?php $attributes = array( 'sales_reciept' => 'sales reciept', 'invoice' => 'invoice' ); echo form_dropdown('transaction_type', $attributes); ?></p> <p><?php echo form_dropdown('customer', $customername); ?></p> <table id="product_table" style="width:100%; border-spacing:0;"> <tr> <th> product name </th> <th> description </th> <th> quantity </th> <th> quantity on hand </th> <th> price </th> </tr> <?php for($index = 1; $index <= $product_num; $index++) { echo ' <tr id="product_info' . $index . '"> <td rowspan="1">' . form_input('product' . $index, 'product', 'class="class-1" id="products"') . '</td> <td rowspan="1">' . form_input('description' . $index, 'description', 'class="class-1" ') . '</td> <td rowspan="1">' . form_input('quantity' . $index, 'quantity', 'class="class-1"') . '</td> <td rowspan="1"><span id="qoh' . $index . '">0</span></td> <td rowspan="1">' . form_hidden('ctrl' . $index, 'ctrl') . '</td> </tr>'; } echo form_hidden('index', $index, 'id="index"'); ?> </table> <table id="tender_info"> <tr id=""> <td><?php echo form_input('elements', '0', 'id="elements"'); ?> </td> <td></td> <td></td> <td><p style="text-align: right"></p></td> <td><?php echo form_input('sub_total', '0.00', 'class="subtotal"'); ?></td> </tr> <tr> <td></td> <td></td> <td></td> <td><?php echo form_dropdown('paymenttype', $payment_type); ?></td> <td><?php echo form_input('paymentamount', 'total', 'class="total"'); ?></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td><?php echo form_input('discountamount', 'discountamount', 'class="class-1"'); ?></td> </tr> </table> <p><?php echo form_input('note', 'note'); ?></p> <?php echo form_hidden('status', 'status'); ?> <p style="padding-top: 15px"><?php echo form_submit('submit', 'create transaction'); ?></p> </div> </div> <?php echo form_close(); ?> the value returned ajax post needs added span id od qoh "rownumber" each row. able value , written script changed of qoh spans same value. have tried using .next() function in jquery changing $('span[id^="qoh"]').html(msg); $(this).next('span').html(msg); not working @ all. tried getting parent of products input , using .last gave me nothing.
change following lines , try ( im not giving whole code here lines change ), hope works.:
<td rowspan="1">' . form_input('product' . $index, 'product', 'class="class-1 prods" id="products_'.$index.'"') . '</td> <td rowspan="1"><span id="qoh_' . $index . '">0</span></td> $('.prods').blur(function () { $('qoh_'+productname).html(msg);
Comments
Post a Comment