Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] pomoc ze skryptem kalkulator
-qpaa-
post
Post #1





Goście







Witam, może mi ktoś pomuc ze skryptem znalazłem kod bardzo podobny do tego co chciałem osiągnąć przerobiłem go do moich potrzeb niestety nie działa mnożenie kolum. Moge prosić o pomoc, co zrobiłem nie tak (IMG:style_emoticons/default/questionmark.gif) ?

oryginalny:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dokument bez tytułu</title>

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">// <![CDATA[
google.load("jquery", "1");
// ]]></script>
<script type="text/javascript">// <![CDATA[
function update(){
var sum = 0;
$("#calculator > tbody > tr").each(function(){
var price = parseFloat($(this).find("td:eq(2)").text());
var amount = parseFloat($(this).find("td:eq(3)").find("input:first").val());
var value = $(this).find("td:eq(4)");
if (amount > 0) {
value.text(price*amount);
sum += price*amount;
} else {
value.text(0);
}
});
$("#summary").text(sum);
}
$(document).ready(function(){
update();
$("#calculator input").keyup(function(){
update();
});
});
// ]]></script>

</head>

<body>


<h2>Kalkulator kosztów</h2>
<table id="calculator" style="border-style: solid; border-width: 0pt; padding: 7px; background-color: #edede5;" border="0">
<thead>
<tr>
</tr>
<tr style="text-align: center;">
<th><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;">Rodzaj operacji <br /></span></th> <th style="text-align: right;"><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;">Jm <br /></span></th> <th style="text-align: right;"><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;"> Przelicznik <br /></span></th> <th><span style="font-size: 10pt; color: #6c9107; font-family: tahoma,arial,helvetica,sans-serif;">Ilość</span></th> <th style="text-align: right;"><span style="color: #6c9107; font-family: tahoma,arial,helvetica,sans-serif;"><span style="font-size: 10pt;">Wartość w z</span>ł</span></th>
</tr>
</thead> <tfoot>
<tr>
<th style="text-align: right;" colspan="4"><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;">Razem</span></th> <th id="summary" style="text-align: right;"> <br /> </th>
</tr>
</tfoot>
<tbody>
<tr>
<td><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">Czas spędzony na zakup</span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Godz.</span></td>
<td style="text-align: right;"><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">8,00 x</span><br /></td>
<td><input name="czas_zakupu" type="text" /></td>
<td style="text-align: right;"><br /></td>
</tr>
<tr>
<td><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Czas spędzony na dojazd<br /></span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Godz. <br /></span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">8,00 x</span><br /></td>
<td><input name="czas_dojazdu" type="text" /></td>
<td style="text-align: right;"><br /></td>
</tr>
<tr>
<td><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Ilość spalonych litrów</span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">L</span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">4,26 x</span><br /></td>
<td><input name="spalone_litry" type="text" /></td>
<td style="text-align: right;"><br /></td>
</tr>
<tr>
<td><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">Amortyzacja auta</span></td>
<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Am</span></td>
<td style="text-align: right;"><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">1 x</span><br /></td>
<td><input name="amortyzacja" type="text" /></td>
<td style="text-align: right;"><br /></td>
</tr>
</tbody>
</table>



</body>
</html>

przerobiony:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dokument bez tytułu</title>

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">// <![CDATA[
google.load("jquery", "1");
// ]]></script>
<script type="text/javascript">// <![CDATA[
function update(){
var sum = 0;
$("#calculator > tbody > tr").each(function(){


var amount = parseFloat($(this).find("td:eq(2)").find("input:first").val());

var value = $(this).find("td:eq(3)");

if (amount > 0) {
value.text(price*amount);
sum += price*amount;
} else {
value.text(0);
}

var price = $(this).find("td:eq(1)");
if (amount > 0 && amount < 501) {
price.text(12);
} else
if (amount > 500 && amount < 3000) {
price.text(9);

}


});
$("#summary").text(sum);
}
$(document).ready(function(){
update();
$("#calculator input").keyup(function(){
update();
});
});
// ]]></script>

</head>

<body>


<h2>Kalkulator cen</h2>
<table id="calculator" style="border-style: solid; border-width: 0pt; padding: 7px; background-color: #edede5;" border="0">
<thead>
<tr>
</tr>
<tr style="text-align: center;">
<th><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;">Towar <br /></span></th> <th style="text-align: right;"><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;"> Cena <br /></span></th> <th><span style="font-size: 10pt; color: #6c9107; font-family: tahoma,arial,helvetica,sans-serif;">Ilość</span></th> <th style="text-align: right;"><span style="color: #6c9107; font-family: tahoma,arial,helvetica,sans-serif;"><span style="font-size: 10pt;">Wartość w z</span>ł</span></th>


</tr>
</thead> <tfoot>
<tr>
<th style="text-align: right;" colspan="3"><span style="font-size: 10pt; font-family: tahoma,arial,helvetica,sans-serif; color: #6c9107;">Razem</span></th> <th id="summary" style="text-align: right;"> <br /> </th>
<th id="summary" style="text-align: right;"> <br /> </th>
</tr>
</tfoot>
<tbody>
<tr>
<td><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">Towar1</span></td>

<td style="text-align: right;"><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;"></span><br /></td>
<td><input type="text" /></td>
<td style="text-align: right;"><br /></td>

</tr>
<tr>
<td><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Towar 2<br /></span></td>

<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;"></span><br /></td>
<td><input type="text" /></td>
<td style="text-align: right;"><br /></td>

</tr>
<tr>
<td><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;">Towar 3</span></td>

<td style="text-align: right;"><span style="font-size: 8pt; font-family: tahoma,arial,helvetica,sans-serif;"></span><br /></td>
<td><input type="text" /></td>
<td style="text-align: right;"><br /></td>

</tr>
<tr>
<td><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;">Towar 4</span></td>

<td style="text-align: right;"><span style="font-family: tahoma,arial,helvetica,sans-serif; font-size: 8pt;"></span><br /></td>
<td><input type="text" /></td>
<td style="text-align: right;"><br /></td>

</tr>
</tbody>
</table>



</body>
</html>

Go to the top of the page
+Quote Post

Posty w temacie
- qpaa   [JavaScript] pomoc ze skryptem kalkulator   1.12.2013, 19:50:23
- - werdan   http://jsfiddle.net/8JWkN/   1.12.2013, 21:29:03
- - qpaa   Dziękuję bardzo za pomoc, super teraz działa jak n...   1.12.2013, 22:09:55
- - qpaa   dlaczego przestaje działać jak zmieniam ceny na np...   3.12.2013, 08:12:26
- - werdan   Zmień: [HTML] pobierz, plaintext var _price = pars...   3.12.2013, 09:05:01
- - qpaa   Dzięki jeszcze raz   3.12.2013, 10:36:00
- - qpaa   Mogę liczyć jeszcze na jakieś wskazuwki, przerobił...   5.12.2013, 08:35:40
- - qpaa   kombinuję ale coś nie za bardzo wychodzi. Pomocy ...   6.12.2013, 20:56:10
- - qpaa   Jak uzyskać sumę kolumny wartość ? oraz o to co ju...   13.12.2013, 14:28:17
- - qpaa   pomocy http://jsfiddle.net/8JWkN/7/   17.12.2013, 10:42:06


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 15:53