<?php include "koneksi.php"; $sql = "SELECT * FROM tbpeg ORDER by nama"; $hasil = mysql_query($sql); ?> <tr> <td><label for="cbonm[0]"></label> <select name="cbonm[0]" onChange="cari(this.value)"> <option value=" " selected> </option> <?php while($data=mysql_fetch_array($hasil)){ echo "<option value=$data[nip]>$data[nama]</option>"; } ?> </select> </td> <td><input name="txtpangkat[0]" type="text" id="txtpangkat" readonly="readonly" /></td> <td><input name="txtdivi[0]" type="text" id="txtdivi" size="25" readonly="readonly" /></td> <td><textarea name="txtperanan[0]" id="txtperanan"></textarea></td> <td><button type="button" class="del">Hapus</button></td> </tr> <tr id ="last"> <td colspan="5"><button type="button" id="addRow"> Tambah </button></td> </tr> </table> <table width="646" border="0"> <tr> <td width="544" align="right"><input type="submit" name="cmdsimpan" id="cmdsimpan" value=" Simpan " /></td> <td width="10" align="right"> </td> <td width="80" align="right"><input type="submit" name="cmdbatal" id="cmdbatal" value=" Batal " /></td> </tr> </table> </form> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> var i = 1; $(function(){ $("#addRow").click(function(){ row = '<tr>'+ '<td><select name="cbonm['+i+']"</select></td>'+ '<td><input type="text" name="txtpangkat" readonly="readonly['+i+']"/></td>'+ '<td><input type="text" name="txtdivi" size="25" readonly="readonly['+i+']"/></td>'+ '<td><textarea name="txtperanan['+i+']"/></td>'+ '<td><button type="button" class="del">Hapus</button></td>'+ '</tr>'; $(row).insertBefore("#last"); i++; }); }); $(".del").live('click', function(){ $(this).parent().parent().remove(); }); </script>
<?php include "koneksi.php"; $sql = "SELECT * FROM tbpeg ORDER by nama"; $hasil = mysql_query($sql); ?> <table> <tr id ="last"> <td colspan="5"><button type="button" id="addRow"> Tambah </button></td> </tr> </table> <table width="646" border="0"> <tr> <td width="544" align="right"><input type="submit" name="cmdsimpan" id="cmdsimpan" value=" Simpan " /></td> <td width="10" align="right"> </td> <td width="80" align="right"><input type="submit" name="cmdbatal" id="cmdbatal" value=" Batal " /></td> </tr> </table> </form> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> var i = 0; $(function(){ $("#addRow").click(function(){ row = '<tr>'+ '<td>'+ '<select name="cbonm['+i+']" onChange="cari(this.value)">'+ '<option value="" selected> </option>'+ '<?php while($data=mysql_fetch_array($hasil)){ echo '<option value="'.$data['nip'].'">'.$data['nama'].'</option>'; }?>'+ '</select>'+ '</td>'+ '<td><input name="txtpangkat['+i+']" type="text" id="txtpangkat-'+i+'" readonly="readonly" /></td>'+ '<td><input name="txtdivi['+i+']" type="text" id="txtdivi-'+i+'" size="25" readonly="readonly" /></td>'+ '<td><textarea name="txtperanan['+i+']" id="txtperanan-'+i+'"></textarea></td>'+ '<td><button type="button" class="del">Hapus</button></td>'+ '</tr>'; $(row).insertBefore("#last"); i++; }); $(".del").live('click', function(){ $(this).parent().parent().remove(); }); $("#addRow").click(); }); </script>