Personal I have a foreach populating 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 want to pass the product price as I need to display it in the table as image below, I tried to do with input hidden, like this:
<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 the next products are out of select, as below:
ThisdataIgetinjavaScriptthisway:
$('.preview-add-button').click(function(){varform_data={};vardados={};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 it? Or some other way to pass the price?
Thank you.