I hava an error javascript. This javascript create a dynamic table add and remove.
In reality, the script is correct and work perfetly but, inside my tools I hava a function than create a problem with this javascript and I want know if it's possible to modify this javascript.
The problem come from this element who create a dropdown (HTML::selectMenu
)
<td class='col-md-2'><?php echo HTML::selectMenu('suppliers_id[["+i+"]', $OSCOM_ProductsAdmin->SupplierDropDown()); ?>
I have this function than can't touch else this site does'nt work.
public static function output($string, $translate = null) {
if (!isset($translate)) {
$translate = ['"' => '"'];
}
return strtr(trim($string), $translate);
}
inside the the html HTML::selectMenu
function (dropdown) I have inside
$field = '<select name="' . static::output($name) . '"';
When I edit my htmlpage generated this code become
<select name="suppliers_id[["+i+"]" id="suppliers_id[["+i+"]" class="form-control"><option value="">--Aucun--</option><option value="1">test</option></select>
and the problem come here : ["+i+"]
and must be ['+i+']
(like the javascript)
How to resolve the problem ?
Thank you
<script>
$(document).ready(function(){
var i=<?php echo $id-1; ?>;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td>" +
"<td class='col-md-2'><input name='id["+i+"]' type='text' placeholder='Name' class='form-control' /> </td><td class='col-md-2'><?php echo HTML::selectMenu('suppliers_id[["+i+"]', $OSCOM_ProductsAdmin->SupplierDropDown()); ?></td><td class='col-md-2'><input name='discount_quantity["+i+"]' type='text' placeholder='Qty' class='form-control'></td><td class='col-md-2'><input name='discount_supplier_price["+i+"]' type='text' placeholder='Supplier Price' class='form-control'></td><td class='col-md-2'><input name='discount_customer["+i+"]' type='text' placeholder='Without %' class='form-control'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
</script>