Amita Singh
asked on
add more button stop working when i used dynamic dropdown from database
Hi,
for client drop down i am using chosen(for search client name and multiple selection). my problem is when i use client drop down in java script for add more row, add more button stop working and when i comment the code add more button is working. code given below.
Javascript code for add more row
for client drop down i am using chosen(for search client name and multiple selection). my problem is when i use client drop down in java script for add more row, add more button stop working and when i comment the code add more button is working. code given below.
<?php //echo $fet_client["clients"] ?>
html_code += '<td><select name="client[]" id="client'+count+'" class="chosen form-control input-sm"><option value="">Select Client</option><?php $client = mysql_query("SELECT * FROM clients ");while($fet_client=mysql_fetch_array($client)){?><option value="<?php echo $fet_client["cl_id"];?>"><?php //echo $fet_client["clients"] ?></option><?php } ?></select></td>';
Html code is here<tr>
<td><span id="sr_no">1</span></td>
<td>
<select name="client[]" id="client" class="chosen form-control input-sm">
<option value="">Select Client</option>
<?php $client = mysql_query("SELECT * FROM clients ");
while($fet_client=mysql_fetch_array($client)){
?>
<option value="<?php echo $fet_client['cl_id'];?>"><?php echo $fet_client['clients'];?></option>
<?php } ?>
</select>
</td>
<td><input type="text" name="invoice_no[]" id="invoice_no" class="form-control input-sm" value="" required /></td>
<td><input type="text" name="job_no[]" id="job_no" class="form-control input-sm" value="" /></td>
<td><input type="text" name="receiving_date[]" id="datepicker" class="form-control input-sm" value="" required /></td>
<td><input type="text" name="on_ac[]" id="on_ac" class="form-control input-sm" value="" /></td>
<td><input type="text" name="received_amount[]" id="received_amount" class="form-control input-sm number_only" value="" /></td>
<td><input type="text" name="tds[]" id="tds" class="form-control input-sm number_only" value="" /></td>
<td><input type="text" name="added_by[]" id="added_by" class="form-control input-sm" value="" /></td>
<td><input type="text" name="remark[]" id="remark" class="form-control input-sm" value="" /></td>
<td></td>
</tr>
Javascript code for add more row
var count = 1;
$('#datepicker').datepicker();
$(document).on('click', '#add_row', function(){
count++;
$('#total_item').val(count);
var html_code = '';
html_code += '<tr id="row_id_'+count+'">';
html_code += '<td><span id="sr_no">'+count+'</span></td>';
html_code += '<td><select name="client[]" id="client'+count+'" class="chosen form-control input-sm"><option value="">Select Client</option><?php $client = mysql_query("SELECT * FROM clients ");while($fet_client=mysql_fetch_array($client)){?><option value="<?php echo $fet_client["cl_id"];?>"><?php echo $fet_client["clients"] ?></option><?php } ?></select></td>';
html_code += '<td><input required type="text" name="invoice_no[]" id="invoice_no'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="job_no[]" id="job_no'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input required type="text" name="receiving_date[]" id="datepicker'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="on_ac[]" id="on_ac'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="received_amount[]" id="received_amount'+count+'" class="form-control input-sm number_only" /></td>';
html_code += '<td><input type="text" name="tds[]" id="tds'+count+'" class="form-control input-sm number_only" /></td>';
html_code += '<td><input type="text" name="added_by[]" id="added_by'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><input type="text" name="remark[]" id="remark'+count+'" class="form-control input-sm" /></td>';
html_code += '<td><button type="button" name="remove_row" id="'+count+'" class="btn btn-danger btn-xs remove_row">X</button></td>';
html_code += '</tr>';
$('#invoice-item-table').append(html_code);
$('#datepicker'+ count).datepicker();
$('#client_chosen'+ count).chosen();
});
please find the attachment.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also I believe :
$cli = $fet_client["clients"];
should be something like this instead :
$cli = $fet_client["cl_name"];
I don't have the clients table schema but I'm assuming this as your client id is : cl_id
$cli = $fet_client["clients"];
should be something like this instead :
$cli = $fet_client["cl_name"];
I don't have the clients table schema but I'm assuming this as your client id is : cl_id
ASKER
Thank You.
Open in new window