Advertisement
freddy0512

test

Mar 30th, 2015
462
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 1 0
  1.  
  2. $(".delete").on('click', function() {
  3. $('.case:checkbox:checked').parents("tr").remove();
  4. $('.check_all').prop("checked", false);
  5. check();
  6. });
  7. var i=$('table tr').length;
  8.  
  9. $(".addmore").on('click',function(){
  10. count=$('table tr').length;
  11. var data="<tr><td><input type='checkbox' class='case'/></td><td><span id='snum"+i+"'>"+count+".</span></td>";
  12. 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>";
  13.  
  14. //i just add onkeyup in input type harga and jumlah
  15.  
  16.  
  17. $('table').append(data);
  18. row = i ;
  19. $('#kodebarang_'+i).autocomplete({
  20. source: function( request, response ) {
  21. $.ajax({
  22. url: 'http://localhost/code_cipta/item',
  23. dataType: "json",
  24. method: 'post',
  25. data: {
  26. name_startsWith: request.term,
  27. type: 'country_table',
  28. row_num : row
  29. },
  30. success: function( data ) {
  31.  
  32. response( $.map( data, function( item ) {
  33. var code = item.split("|");
  34. return {
  35. label: code[0],
  36. value: code[0],
  37. data : item
  38. }
  39. }));
  40. }
  41. });
  42. },
  43. autoFocus: true,
  44. minLength: 0,
  45. select: function( event, ui ) {
  46. var names = ui.item.data.split("|");
  47. id_arr = $(this).attr('id');
  48. id = id_arr.split("_");
  49. $('#namabarang_'+id[1]).val(names[1]);
  50. $('#stock_'+id[1]).val(names[2]);
  51. }
  52.  
  53. });
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. //buat taruh data telp
  64. $('#stock_'+i).autocomplete({
  65. source: function( request, response ) {
  66. $.ajax({
  67. url: 'http://localhost/code_cipta/item',
  68. dataType: "json",
  69. method: 'post',
  70. data: {
  71. name_startsWith: request.term,
  72. type: 'country_table',
  73. row_num : row
  74. },
  75. success: function( data ) {
  76. response( $.map( data, function( item ) {
  77. var code = item.split("|");
  78. return {
  79. label: code[2],
  80. value: code[2],
  81. data : item
  82. }
  83. }));
  84. }
  85. });
  86. },
  87. autoFocus: true,
  88. minLength: 0,
  89. select: function( event, ui ) {
  90. var names = ui.item.data.split("|");
  91. id_arr = $(this).attr('id');
  92. id = id_arr.split("_");
  93. $('#namabarang_'+id[1]).val(names[1]);
  94. $('#kodebarang_'+id[1]).val(names[0]);
  95. }
  96. });
  97.  
  98. //buat taruh data no negara
  99. $('#namabarang_'+i).autocomplete({
  100. source: function( request, response ) {
  101. $.ajax({
  102. url: 'http://localhost/code_cipta/item',
  103. dataType: "json",
  104. method: 'post',
  105. data: {
  106. name_startsWith: request.term,
  107. type: 'country_table',
  108. row_num : row
  109. },
  110. success: function( data ) {
  111. response( $.map( data, function( item ) {
  112. var code = item.split("|");
  113. return {
  114. label: code[1],
  115. value: code[1],
  116. data : item
  117. }
  118. }));
  119. }
  120. });
  121. },
  122. autoFocus: true,
  123. minLength: 0,
  124. select: function( event, ui ) {
  125. var names = ui.item.data.split("|");
  126. id_arr = $(this).attr('id');
  127. id = id_arr.split("_");
  128. $('#stock_'+id[1]).val(names[2]);
  129. $('#kodebarang_'+id[1]).val(names[0]);
  130. }
  131. });
  132.  
  133. i++;
  134. });
  135.  
  136.  
  137. //buat delete all
  138. function select_all() {
  139. $('input[class=case]:checkbox').each(function(){
  140. if($('input[class=check_all]:checkbox:checked').length == 0){
  141. $(this).prop("checked", false);
  142. } else {
  143. $(this).prop("checked", true);
  144. }
  145. });
  146. }
  147.  
  148. //buat check all
  149. function check(){
  150. obj=$('table tr').find('span');
  151. $.each( obj, function( key, value ) {
  152. id=value.id;
  153. $('#'+id).html(key+1);
  154. });
  155. }
  156.  
  157. //buat ambil nilai country name
  158. $('#kodebarang_1').autocomplete({
  159.  
  160. source: function( request, response ) {
  161.  
  162. $.ajax({
  163. url: 'http://localhost/code_cipta/item',
  164. dataType: "json",
  165. method: 'post',
  166. data: {
  167. name_startsWith: request.term,
  168. type: 'country_table',
  169. row_num : 1
  170. },
  171. success: function( data ) {
  172.  
  173.  
  174. //alert ('KETEMU');
  175.  
  176. response( $.map( data, function( item ) {
  177. //alert();
  178. var code = item.split("|");
  179. return {
  180. label: code[0],
  181. value: code[0],
  182. data : item
  183. }
  184. }));
  185.  
  186.  
  187. }
  188. });
  189. },
  190. autoFocus: true,
  191. minLength: 0,
  192. select: function( event, ui ) {
  193.  
  194. var names = ui.item.data.split("|");
  195. $('#namabarang_1').val(names[1]);
  196. $('#stock_1').val(names[2]);
  197. }
  198. });
  199.  
  200.  
  201.  
  202. $('#namabarang_1').autocomplete({
  203. source: function( request, response ) {
  204. $.ajax({
  205. url: 'http://localhost/code_cipta/item',
  206. dataType: "json",
  207. method: 'post',
  208. data: {
  209. name_startsWith: request.term,
  210. //ini nama field yang di form
  211. type: 'namabarang',
  212. row_num : 1
  213. },
  214. success: function( data ) {
  215. response( $.map( data, function( item ) {
  216. var code = item.split("|");
  217. return {
  218. label: code[1],
  219. value: code[1],
  220. data : item
  221. }
  222. }));
  223. }
  224. });
  225. },
  226. autoFocus: true,
  227. minLength: 0,
  228. select: function( event, ui ) {
  229. var names = ui.item.data.split("|");
  230. $('#stock_1').val(names[2]);
  231. $('#kodebarang_1').val(names[0]);
  232. },
  233. open: function() {
  234. $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
  235. },
  236. close: function() {
  237. $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
  238. }
  239. });
  240. //kasih phone code
  241. $('#stock_1').autocomplete({
  242. source: function( request, response ) {
  243. $.ajax({
  244. url: 'http://localhost/code_cipta/item',
  245. dataType: "json",
  246. method: 'post',
  247. data: {
  248. name_startsWith: request.term,
  249. type: 'stock',
  250. row_num : 1
  251. },
  252. success: function( data ) {
  253. response( $.map( data, function( item ) {
  254. var code = item.split("|");
  255. return {
  256. label: code[2],
  257. value: code[2],
  258. data : item
  259. }
  260. }));
  261. }
  262. });
  263. },
  264. autoFocus: true,
  265. minLength: 0,
  266. select: function( event, ui ) {
  267. var names = ui.item.data.split("|");
  268. $('#jumlah_1 ').val(names[3]);
  269. $('#namabarang_1 ').val(names[1]);
  270. $('#kodebarang_1').val(names[0]);
  271. },
  272. open: function() {
  273. $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
  274. },
  275. close: function() {
  276. $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
  277. }
  278. });
  279. function hitung2(el) {
  280. var row = $(el).closest("tr"),
  281. inputs = row.find("[type=text]")
  282. jumlah = inputs.eq(3).val(),
  283. harga = inputs.eq(4).val();
  284. inputs.eq(5).val(jumlah * harga)
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement