0
I don’t know much about you, so I need some help. I have a page that generates a form with a quotation map, in columns (each supplier in a column), and I need the user to select the checkbox he make the sum online because each supplier has a minimum value to be able to authorize the billing.
The point is that the script uses the name=days[] in all checkboxes, and I need a different name for each vendor, this I can do by php using variables, but how I do so js can create multiple codes by taking the name of my checkbox variable ?
Part of php code that generates the result and the checkbox:
#Monta listagem de valores referente ao produtos
//selecionando os valores
$sqlValores = "SELECT v.total, id_precos, v.preco
FROM tbl_cot_precos AS v
WHERE id_produto = '" .$produtos['produtosCod'][$i]. "'
AND v.id_pedido =$id_pedido";
$resValores = mysql_query($sqlValores);
while ($listaValores = mysql_fetch_array($resValores))
{
//exibe valores
echo '<td align="right"><input type="text" style="font-family: Tahoma; font-size: 10px" size="12" name="valor_unit" value="' .number_format($listaValores[2], 2, ',', '.'). '" readonly="readonly"></td>
<td align="right"><input type="text" style="font-family: Tahoma; font-size: 10px" size="12" name="valor_total" value="' .number_format($listaValores[0], 2, ',', '.'). '" readonly="readonly"></td>
<td style="display:none;"><input type="hidden" name="produto_id_'.$listaValores[1].'" value="'.$listaValores[1].'"></td>
<td style="display:none;"><input type="hidden" name="pedido" value="'.$id_pedido.'"></td>
<td><input type="checkbox" class="dias" name="dias[]" value="'.$listaValores[0].'"></td>';
}
$i++;
#Fim monta listagem de preços referente ao produtos
echo '</tr>';
js making the online checkbox sum that are clicked:
<script type="text/javascript">
jQuery(function() {
$(document).ready(function() {
$(".dias").change(function() {
var total = $('input[class="dias"]:checked').get().reduce(function(tot, el) {
return tot + Number(el.value);
}, 0);
$('#resultado').val(total);
});
});
});
</script>
You need to create many code and want to store where? First in array or directly in the database?
– adventistaam
Where does the identification of each supplier enter into it?
– Sam
The suppliers' data and the prices of each one are already in the comic book, in this routine I only demonstrate to the user, the issue is that as he can buy products from several suppliers, I need him to make the sum and confront with the minimum purchase value information. So you need JS to be able to get the checkbox ID of each vendor, the checkbox ID name I can for example assign the vendor code, but how JS will know that name ?
– henrique antevere
Here in the code I can add the vendor code in the BD <td><input type="checkbox" class="days" name="dias_$id_vendor[]" value="'. $listaValores[0]. '"></td>';
– henrique antevere
You want the check name to assign the code?
– adventistaam