repetir autocompletado al agregar items
Publicado por elizabeth laguna (8 intervenciones) el 21/08/2019 00:42:24
buenas tardes, alguien sabe somo puedo hacer que se repita el mismo autocompletado al agregar items cuando tecleo el producto por favor.
esta es la tabla donde empiezo a teclear
y este es mi archivo .js donde mando llamar por medio de una funcion para que agregue items por medio de un boton
esta es la tabla donde empiezo a teclear
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<table class="table table-bordered table-hover" id="invoiceItem">
<tr>
<th width="2%"><input id="checkAll" class="formcontrol" type="checkbox"></th>
<th width="15%">Prod. No</th>
<th width="38%">Nombre Producto</th>
<th width="15%">Cantidad</th>
<th width="15%">Precio</th>
<th width="15%">Total</th>
</tr>
<tr class="fila-fija">
<td><input class="itemRow" type="checkbox"></td>
<td class="input_container"><input type="text" name="productCode[]" id="productCode_1" class="form-control" onkeyup="autocompletar()">
<ul id="lista_id"></ul>
</td>
<td class="input_container"><input type="text" name="productName[]" id="productName_1" class="form-control" autocomplete="off">
</td>
<td><input type="number" name="quantity[]" id="quantity_1" class="form-control quantity" autocomplete="off"></td>
<td><input type="number" name="price[]" id="price_1" class="form-control price" autocomplete="off"></td>
<td><input type="number" name="total[]" id="total_1" class="form-control total" autocomplete="off"></td>
</tr>
<!-- esta es autocompletado con javascript -->
</table>
</div>
y este es mi archivo .js donde mando llamar por medio de una funcion para que agregue items por medio de un boton
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
$(document).ready(function(){
$(document).on('click', '#checkAll', function() {
$(".itemRow").prop("checked", this.checked);
});
$(document).on('click', '.itemRow', function() {
if ($('.itemRow:checked').length == $('.itemRow').length) {
$('#checkAll').prop('checked', true);
} else {
$('#checkAll').prop('checked', false);
}
});
var count = $(".itemRow").length;
$(document).on('click', '#addRows', function() {
count++;
var htmlRows = '';
htmlRows += '<tr>';
htmlRows += '<td><input class="itemRow" type="checkbox"></td>';
htmlRows += '<td><input type="text" name="productCode[]" id="productCode_'+count+'" class="control" autocomplete="off" onkeyup="autocompletar()"><ul id="lista_id"></ul></td>';
htmlRows += '<td><input type="text" name="productName[]" id="productName_'+count+'" class="control" autocomplete="off"></td>';
htmlRows += '<td><input type="number" name="quantity[]" id="quantity_'+count+'" class="control" autocomplete="off"></td>';
htmlRows += '<td><input type="number" name="price[]" id="price_'+count+'" class="control" autocomplete="off"></td>';
htmlRows += '<td><input type="number" name="total[]" id="total_'+count+'" class="control" autocomplete="off"></td>';
htmlRows += '</tr>';
$('#invoiceItem').append(htmlRows);
});
$(document).on('click', '#removeRows', function(){
$(".itemRow:checked").each(function() {
$(this).closest('tr').remove();
});
$('#checkAll').prop('checked', false);
calculateTotal();
});
$(document).on('blur', "[id^=quantity_]", function(){
calculateTotal();
});
$(document).on('blur', "[id^=price_]", function(){
calculateTotal();
});
$(document).on('blur', "#taxRate", function(){
calculateTotal();
});
$(document).on('blur', "#amountPaid", function(){
var amountPaid = $(this).val();
var totalAftertax = $('#totalAftertax').val();
if(amountPaid && totalAftertax) {
totalAftertax = totalAftertax-amountPaid;
$('#amountDue').val(totalAftertax);
} else {
$('#amountDue').val(totalAftertax);
}
});
$(document).on('click', '.deleteInvoice', function(){
var id = $(this).attr("id");
if(confirm("Are you sure you want to remove this?")){
$.ajax({
url:"action.php",
method:"POST",
dataType: "json",
data:{id:id, action:'delete_invoice'},
success:function(response) {
if(response.status == 1) {
$('#'+id).closest("tr").remove();
}
}
});
} else {
return false;
}
});
});
function calculateTotal(){
var totalAmount = 0;
$("[id^='price_']").each(function() {
var id = $(this).attr('id');
id = id.replace("price_",'');
var price = $('#price_'+id).val();
var quantity = $('#quantity_'+id).val();
if(!quantity) {
quantity = 1;
}
var total = price*quantity;
$('#total_'+id).val(parseFloat(total));
totalAmount += total;
});
$('#subTotal').val(parseFloat(totalAmount));
var taxRate = $("#taxRate").val();
var subTotal = $('#subTotal').val();
if(subTotal) {
var taxAmount = subTotal*taxRate/100;
$('#taxAmount').val(taxAmount);
subTotal = parseFloat(subTotal)+parseFloat(taxAmount);
$('#totalAftertax').val(subTotal);
var amountPaid = $('#amountPaid').val();
var totalAftertax = $('#totalAftertax').val();
if(amountPaid && totalAftertax) {
totalAftertax = totalAftertax-amountPaid;
$('#amountDue').val(totalAftertax);
} else {
$('#amountDue').val(subTotal);
}
}
}
Valora esta pregunta


0