jquery - Dynamics Variable (variable++) in Append function DOM Javascript -
i have code
function add_fullboard_dalam_kota(){ var data='<?php echo $data; ?>'; var tambah=1; var txt=1; $("#fullboard_dalam_kota").append('<tr align="center" valign="middle"bgcolor="#e4e4e4">' +'<td width="19%" ><input name="penyelenggara[]" type="text" id="'+tambah+'" onchange="showuser(this.value)"></td>' +'<td width="19%" ><div id="'+txt+'"><b></b></div>' +'</td>' +'<td width="19%" ><input name="jumlah_peserta[]" type="text" id="jumlah_peserta[]"></td>' +'<td width="19%" ><input name="jumlah_hari[]" type="text" id="jumlah_hari[]"></td>' +'</tr>') tambah=tambah+1; txt=txt+1; alert(tambah);
my question why value of "tambah" variable 2? , how make dynamically added 1 after 1 append() function called?
declare variable "tambah" outside of function.
//declare variable outside scope of fucn() var tambah=1; function add_fullboard_dalam_kota(){ var data='<?php echo $data; ?>'; var txt=1; $("#fullboard_dalam_kota").append('<tr align="center" valign="middle"bgcolor="#e4e4e4">' +'<td width="19%" ><input name="penyelenggara[]" type="text" id="'+tambah+'" onchange="showuser(this.value)"></td>' +'<td width="19%" ><div id="'+txt+'"><b></b></div>' +'</td>' +'<td width="19%" ><input name="jumlah_peserta[]" type="text" id="jumlah_peserta[]"></td>' +'<td width="19%" ><input name="jumlah_hari[]" type="text" id="jumlah_hari[]"></td>' +'</tr>') tambah++; txt++; alert(tambah); }
Comments
Post a Comment