Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(".delete").on('click', function() {
- $('.case:checkbox:checked').parents("tr").remove();
- $('.check_all').prop("checked", false);
- check();
- });
- var i=$('table tr').length;
- $(".addmore").on('click',function(){
- count=$('table tr').length;
- var data="<tr><td><input type='checkbox' class='case'/></td><td><span id='snum"+i+"'>"+count+".</span></td>";
- data +="<td><input class='form-control' type='text' id='kodebarang_"+i+"' name='kodebarang[]'/></td> <td><input class='form-control' type='text' id='namabarang_"+i+"' name='namabarang[]'/></td><td><input class='form-control' type='text' id='stock_"+i+"' name='stock[]'/></td><td><input class='form-control' type='text' id='jumlah_"+i+"' name='jumlah[]' onkeyup='hitung2(this);' /></td><td><input class='form-control' type='text' id='harga_"+i+"' name='harga[]' onkeyup='hitung2(this);' /></td><td><input class='form-control' type='text' id='total_"+i+"' name='total[]'/></td></tr>";
- //i just add onkeyup in input type harga and jumlah
- $('table').append(data);
- row = i ;
- $('#kodebarang_'+i).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: 'country_table',
- row_num : row
- },
- success: function( data ) {
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[0],
- value: code[0],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- id_arr = $(this).attr('id');
- id = id_arr.split("_");
- $('#namabarang_'+id[1]).val(names[1]);
- $('#stock_'+id[1]).val(names[2]);
- }
- });
- //buat taruh data telp
- $('#stock_'+i).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: 'country_table',
- row_num : row
- },
- success: function( data ) {
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[2],
- value: code[2],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- id_arr = $(this).attr('id');
- id = id_arr.split("_");
- $('#namabarang_'+id[1]).val(names[1]);
- $('#kodebarang_'+id[1]).val(names[0]);
- }
- });
- //buat taruh data no negara
- $('#namabarang_'+i).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: 'country_table',
- row_num : row
- },
- success: function( data ) {
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[1],
- value: code[1],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- id_arr = $(this).attr('id');
- id = id_arr.split("_");
- $('#stock_'+id[1]).val(names[2]);
- $('#kodebarang_'+id[1]).val(names[0]);
- }
- });
- i++;
- });
- //buat delete all
- function select_all() {
- $('input[class=case]:checkbox').each(function(){
- if($('input[class=check_all]:checkbox:checked').length == 0){
- $(this).prop("checked", false);
- } else {
- $(this).prop("checked", true);
- }
- });
- }
- //buat check all
- function check(){
- obj=$('table tr').find('span');
- $.each( obj, function( key, value ) {
- id=value.id;
- $('#'+id).html(key+1);
- });
- }
- //buat ambil nilai country name
- $('#kodebarang_1').autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: 'country_table',
- row_num : 1
- },
- success: function( data ) {
- //alert ('KETEMU');
- response( $.map( data, function( item ) {
- //alert();
- var code = item.split("|");
- return {
- label: code[0],
- value: code[0],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- $('#namabarang_1').val(names[1]);
- $('#stock_1').val(names[2]);
- }
- });
- $('#namabarang_1').autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- //ini nama field yang di form
- type: 'namabarang',
- row_num : 1
- },
- success: function( data ) {
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[1],
- value: code[1],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- $('#stock_1').val(names[2]);
- $('#kodebarang_1').val(names[0]);
- },
- open: function() {
- $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
- },
- close: function() {
- $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
- }
- });
- //kasih phone code
- $('#stock_1').autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: 'http://localhost/code_cipta/item',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: 'stock',
- row_num : 1
- },
- success: function( data ) {
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[2],
- value: code[2],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- $('#jumlah_1 ').val(names[3]);
- $('#namabarang_1 ').val(names[1]);
- $('#kodebarang_1').val(names[0]);
- },
- open: function() {
- $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
- },
- close: function() {
- $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
- }
- });
- function hitung2(el) {
- var row = $(el).closest("tr"),
- inputs = row.find("[type=text]")
- jumlah = inputs.eq(3).val(),
- harga = inputs.eq(4).val();
- inputs.eq(5).val(jumlah * harga)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement