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 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
 
Start new topic
Odpowiedzi (1 - 9)
werdan
post
Post #2





Grupa: Zarejestrowani
Postów: 354
Pomógł: 100
Dołączył: 14.11.2013
Skąd: Płock

Ostrzeżenie: (0%)
-----


http://jsfiddle.net/8JWkN/
Go to the top of the page
+Quote Post
-qpaa-
post
Post #3





Goście







Dziękuję bardzo za pomoc, super teraz działa jak należy.
Go to the top of the page
+Quote Post
-qpaa-
post
Post #4





Goście







dlaczego przestaje działać jak zmieniam ceny na np. 0.12, 0.9 ?
Go to the top of the page
+Quote Post
werdan
post
Post #5





Grupa: Zarejestrowani
Postów: 354
Pomógł: 100
Dołączył: 14.11.2013
Skąd: Płock

Ostrzeżenie: (0%)
-----


Zmień:
  1. var _price = parseInt(price.text());

na
  1. var _price = parseFloat(price.text());
Go to the top of the page
+Quote Post
-qpaa-
post
Post #6





Goście







Dzięki jeszcze raz
Go to the top of the page
+Quote Post
-qpaa-
post
Post #7





Goście







Mogę liczyć jeszcze na jakieś wskazuwki, przerobiłem trochę skrypt. Napotkałem kolejny problem a mianowicie chciałem osiągnąć coś takiego, że po wybraniu towaru 1 lub 4 lub 7 lub wszystkich 3 razem nie są naliczane koszty dodatkowe czyli 0, natopiast w przypaku wybrania towaru 2,3,5,6 jest naliczony koszt np. 60. Koszt 60 jest naliczany zasze jak jest wybieramy któryś towar 2,3,5,6 lub wszystkie razem nawet jak zostały wybrane pozostałe towary 1,2,7 to wraz z towarem 2,3,5,6 i tak zostanie naliczony dodatkowy koszt. Następnie doliczenie kosztu transportu w zależności od wybranej opcji. Mogę prosić o pomoc, jakieś wskazuwki jak to zrobić.

http://jsfiddle.net/8JWkN/3/
Go to the top of the page
+Quote Post
-qpaa-
post
Post #8





Goście







kombinuję ale coś nie za bardzo wychodzi. Pomocy

http://jsfiddle.net/8JWkN/5/
Go to the top of the page
+Quote Post
-qpaa-
post
Post #9





Goście







Jak uzyskać sumę kolumny wartość ?
oraz o to co już pytałem:
po wybraniu towaru 1 lub 4 lub 7 lub wszystkich 3 razem nie są naliczane koszty dodatkowe czyli 0, natopiast w przypaku wybrania towaru 2,3,5,6 jest naliczony koszt np. 60. Koszt 60 jest naliczany zasze jak jest wybieramy któryś towar 2,3,5,6 lub wszystkie razem nawet jak zostały wybrane pozostałe towary 1,2,7 to wraz z towarem 2,3,5,6 i tak zostanie naliczony dodatkowy koszt (nie dziła poprawnie w tej chwili). Proszę o pomoc.

http://jsfiddle.net/8JWkN/6/
(nie wiem dlaczego ale w jsfiddle nie wyświetla kosztu transport, w przeglądach mi to działa)
Go to the top of the page
+Quote Post
-qpaa-
post
Post #10





Goście







pomocy

http://jsfiddle.net/8JWkN/7/
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 04:17