Devo fare una cosa apparentemente semplicissima con questa tabella che mi arriva da un form:
Prodotto | quantità | pr unitario | totale
testo | input | testo | testo
Ho quindi usato jquery calculation che in pratica moltiplica il valore nell'input name quantità per il testo (id) del prezzo unitario per riempire l'id del totale
Il problema è questo: i prodotti con valore 1 nell'input vengono poi calcolati ad ogni aggiornamento, quelli con valore 0 nell'input non vengono più calcolati.codice:jQuery("[id^=total]").calc( // the equation to use for the calculation "qty * price", // define the variables used in the equation, these can be a jQuery object { qty: jQuery("input[name^=qt_]"), price: jQuery("[id^=prezzo_]") }, // define the formatting callback, the results of the calculation are passed to this function function (s){ // return the number as a dollar amount return "€ " + s.toFixed(2); }, // define the finish callback, this runs after the calculation has been complete function ($this){ // sum the total of the $("[id^=total_item]") selector var sum = $this.sum(); jQuery("#grandTotal").text( // round the results to 2 digits "€ " + sum.toFixed(2) ); } );
Se fossero tutti a 1 posso fare quello che voglio, ma ovviamente se un utente ha scelto 0 quantità di un prodotto non posso di certo metterlo a 1.
Qualche idea in proposito?

Rispondi quotando