2
Folks I have a foreach that will populate the select as below:
<select id="status" name="status[]" class="order-type">
<?php foreach ($produtos as $produto) : ?>
<option value="$produto['id']"><?=$produto['nome'];?></option>
<?php
endforeach
?>
</select>
I also want to pass the price of the product because I need to display it in the table as shown below, I tried to do with Hidden input, this way:
<select id="status" name="status[]" class="order-type">
<?php foreach ($produtos as $produto) : ?>
<option value="$produto['id']"><?=$produto['nome'];?></option>
<input type="hidden" name="preco" value="<?=$produto['preco']?>">
<?php
endforeach
?>
</select>
But hence the next products stay out of select, as below:
This data I receive in Java this way:
$('.preview-add-button').click(function(){
var form_data = {};
var dados = {};
form_data["status"] = $('.payment-form #status option:selected').text();
form_data["amount"] = $('.payment-form input[name="amount[]"]').val();
form_data["valor"] = $('.payment-form input[name="valor"]').val();
var valor = getMoney($('.payment-form input[name="valor"]').val());
form_data["total"] = formatReal(("R$ "+form_data["amount"] * valor));
var total = form_data["amount"] * valor;
form_data["remove-row"] = '<span class="ico-cancel"></span>';
var row = $('<tr></tr>');
$.each(form_data, function( type, value ) {
$('<td class="input-'+type+'"></td>').html(value).appendTo(row);
});
$('<input/>').attr("type", "hidden").attr("name", "produto"+ contador + "[]").val(form_data["status"]).appendTo(row);
$('<input/>').attr("type", "hidden").attr("name", "produto"+ contador + "[]").val(form_data["amount"]).appendTo(row);
// $('<input/>').attr("type", "hidden").attr("name", "produto"+ contador + "[]").val(form_data["valor"]).appendTo(row);
contador++;
$('.preview-table > tbody:last').append(row);
sum += total;
$(".preview-total").text(formatReal(sum));
});
Can anyone help me solve? Or some other way to pass the price?
Thank you.
This select is multiple?
– rray
No, it’s simple.
– Eduardo Paludo