tag selector not appear in dynamic form

HSecuritySpec

New Member
I want to display a button on the selector .hapus-baris-makanan when the number of array form of nama-makanan more than one, then a button in the selector .hapus-baris-makanan will appear, but if the number of array-form nama-makanan blank / null , the buttons in the selector .hapus-baris-makanan will be hidden. The following coding I have madehtml\[code\] <form id="formpembayaran" method="post" action="<?php echo base_url('pembayaran/simpanitempembayaran'); ?>"> <table class="table table-striped area-table tabel-form-makanan"> <thead> <tr> <th>Nama Makanan</th> <th>Jenis Makanan</th> <th>Harga Makanan</th> </tr> </thead> <tbody> <tr> <td> <input type="text" name="nama-makanan[]" style="height: 30px; width: 280px;" class="nama-makanan" placeholder="ketikkan nama makanan"/> <input type="hidden" name="id-makanan[]" class="id-makanan"/> </td> <td> <input type="text" readonly name="nama-jenis-makanan[]" style="height: 30px; width: 280px;" class="nama-jenis-makanan" placeholder="nama jenis makanan"/> </td> <td> <input type="text" readonly name="harga-makanan[]" style="height: 30px; width: 280px; text-align: right;" class="harga-makanan" placeholder="harga satuan makanan"/> </td> <td> <a class="btn hapus-baris-makanan"><i class="icon-remove"></i></a> </td> </tr> </tbody> </table>\[/code\]javascript:\[code\]$(document).ready(function(){ var myForm = document.forms.formpembayaran; var idMakanan = myForm.elements['nama-makanan[]']; if (idMakanan.length == null){ $('.hapus-baris-makanan').hide(); } else { $('.hapus-baris-makanan').show(); } $('.tombol-tambah-makanan').on('click', function(){ var tr = '<tr>\n\ <td><input type="text" name="nama-makanan[]" style="height: 30px; width: 280px;" class="nama-makanan" placeholder="ketikkan nama makanan"/><input type="hidden" name="id-makanan[]" class="id-makanan"/></td>\n\ <td><input type="text" readonly name="nama-jenis-makanan[]" style="height: 30px; width: 280px;" class="nama-jenis-makanan" placeholder="nama jenis makanan"/></td>\n\ <td><input type="text" readonly name="harga-makanan[]" style="height: 30px; width: 280px; text-align: right;" class="harga-makanan" placeholder="harga satuan makanan"/></td>\n\ <td><a class="btn hapus-baris-makanan"><i class="icon-remove"></i></a></td>\n\ </tr>'; $("table.tabel-form-makanan tbody").append(tr); }); $('.tombol-reset-makanan').on('click', function(){ $('table.tabel-form-makanan tbody tr:not(:first)').remove(); }); $('.tabel-form-makanan').on( 'click', '.hapus-baris-makanan', function(){ $(this).closest('tr').remove() }); });\[/code\]I do not know the location of the fault. help me please. thank you
 
Back
Top