Potrzebuje prosty kalkulator.
Poszukałem, wyszperałem i mam.
Teraz zmieniłem 1 rzecz i przestał działac.
Kalkulator to tylko taka tableka
Produkt / ilosc / cena / suma
np.
Produkt#1 / 2 / 5 / =10
Poprawny, dzialajacy kod
Kod
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Kalkulator</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
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>
<table id="calculator">
<thead>
<tr>
<th>Rodzaj usługi</th>
<th>Jm</th>
<th>Cena</th>
<th>Ilość</th>
<th>Wartość</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="4">Razem</th>
<th id="summary"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Produkt 1</td>
<td>1 szt</td>
<td>12.00</td>
<td><input type="text" name="gadzie-gipsowe"></td>
<td></td>
</tr>
<tr>
<td>Produkt 2</td>
<td>1 szt.</td>
<td>5.00</td>
<td><input type="text" name="malowanie"></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
<html lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Kalkulator</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
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>
<table id="calculator">
<thead>
<tr>
<th>Rodzaj usługi</th>
<th>Jm</th>
<th>Cena</th>
<th>Ilość</th>
<th>Wartość</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="4">Razem</th>
<th id="summary"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Produkt 1</td>
<td>1 szt</td>
<td>12.00</td>
<td><input type="text" name="gadzie-gipsowe"></td>
<td></td>
</tr>
<tr>
<td>Produkt 2</td>
<td>1 szt.</td>
<td>5.00</td>
<td><input type="text" name="malowanie"></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
Powyzszy dziala, ale ma zadeklarowane ceny.
Chcialby miec 2 kalkulator, gdzie user sam wpisze cene i ilosc.
Zrobilem zmiane w kodzie i tu pojawia sie problem - nie dziala.
Co zle zrobilem?
Sam chcialem, ale juz nie wiem co zle zrobilem.
Pewnie cos prostego :)
Kod
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf 8">
<title>Kalkulator</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
function update(){
var sum = 0;
$("#calculator > tbody > tr").each(function(){
var price = parseFloat($(this).find("td:eq(2)").find("input:first").val());
var amount = parseFloat($(this).find("td:eq(3)").find("input:second").val());
var value = $(this).find("td:eq(4)");
{
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>
<table id="calculator">
<thead>
<tr>
<th>Rodzaj usługi</th>
<th>Jednostki</th>
<th>Cena</th>
<th>Ilość</th>
<th>Wartość</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="4">Razem</th>
<th id="summary"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Produkt 1</td>
<td>1 szt.</td>
<td><input type="text" name="cena1"></td>
<td><input type="text" name="produkt1"></td>
<td></td>
</tr>
<tr>
<td>Produkt 2</td>
<td>1 szt.</td>
<td><input type="text" name="cena2"></td>
<td><input type="text" name="produkt2"></td>
<td></td>
</tr>
</tbody>
</table>
</body>
<meta http-equiv="Content-Type" content="text/html; charset=utf 8">
<title>Kalkulator</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
function update(){
var sum = 0;
$("#calculator > tbody > tr").each(function(){
var price = parseFloat($(this).find("td:eq(2)").find("input:first").val());
var amount = parseFloat($(this).find("td:eq(3)").find("input:second").val());
var value = $(this).find("td:eq(4)");
{
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>
<table id="calculator">
<thead>
<tr>
<th>Rodzaj usługi</th>
<th>Jednostki</th>
<th>Cena</th>
<th>Ilość</th>
<th>Wartość</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="4">Razem</th>
<th id="summary"></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Produkt 1</td>
<td>1 szt.</td>
<td><input type="text" name="cena1"></td>
<td><input type="text" name="produkt1"></td>
<td></td>
</tr>
<tr>
<td>Produkt 2</td>
<td>1 szt.</td>
<td><input type="text" name="cena2"></td>
<td><input type="text" name="produkt2"></td>
<td></td>
</tr>
</tbody>
</table>
</body>
Co w powyzszym kodzie jest zle ze nie dziala?