0
I have an application and in it I use Jquery and the function I’m having problems is as follows:
When the user clicks on the button +
calls Jquery which reads HTML and PHP content and runs in a row below to insert a new record, but with PHP it does not want to work. How do I?
(function($) {
RemoveTableRow = function(handler) {
var tr = $(handler).closest('tr');
tr.fadeOut(400, function() {
tr.remove();
});
return false;
};
var counter = 1;
jQuery('a.add').click(function(event) {
event.preventDefault();
counter++;
var newRow = jQuery(
'<tr>' +
'<td style="width: 300px">' +
'<div class="form-group">' +
'<select name="Produto" id="produto" class="form-control select2" style="width: 100%;">' +
<?php
$sql = "SELECT id_Produto, cod_Produto, dsc_Produto from produtos ORDER BY cod_Produto ASC";
$resultado = mysql_query($sql);
while ($linha = mysql_fetch_array($resultado)) {
$id_Produto = $linha['id_Produto'];
$cod_Produto = $linha['cod_Produto'];
$dsc_Produto = $linha['dsc_Produto'];
echo"<option value='$id_Produto'> $cod_Produto | $dsc_Produto </option>";
}
?>
'</select>' +
'</div> ' +
'</td>' +
'<td id="un"></td>' +
'<td id="vol"><input type="text" class="form-control" name="volume" id="volume" style="width: 50px; margin: 0;"></td>' +
'<td id="qtd"><input type="text" class="form-control" name="quantidade" id="quantidade" style="width: 60px; margin: 0"></td>' +
'<td id="peso"></td>' +
'<td id="uni"></td>' +
'<td id="tot"></td>' +
'<td id="desc"></td>' +
'<td id="liq"></td>' +
'<td></td>' +
'</tr>'
);
jQuery('table.table-bordered').append(newRow);
});
})(jQuery);
Yes it is possible but it will not work the way you expect. Remember that php runs on the server side (only once per request) and javascript on the client side. The most recommended is to use an ajax to mount these combos if they have different values if they are equal can clone the element.
– rray
What do you mean? In what way?
– Lucas Fonseca